Kaydet (Commit) 20910ea8 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

Replace a terribly expensive json parsing with a peek for the value.

We should reduce the amount of callbacks from the core in the first place, so
that we don't have to deduplicate this much here, but this already helps a
lot.

Change-Id: Idf4a3681ac0f47536e00c1d97152f3f8bb99894b
üst 230f04e9
...@@ -446,10 +446,26 @@ bool lcl_isViewCallbackType(const int type) ...@@ -446,10 +446,26 @@ bool lcl_isViewCallbackType(const int type)
int lcl_getViewId(const std::string& payload) int lcl_getViewId(const std::string& payload)
{ {
boost::property_tree::ptree aTree; // this is a cheap way how to get the viewId from a JSON message; proper
std::stringstream aStream(payload); // parsing is terribly expensive, and we just need the viewId here
boost::property_tree::read_json(aStream, aTree); size_t viewIdPos = payload.find("viewId");
return aTree.get<int>("viewId"); if (viewIdPos == std::string::npos)
return 0;
size_t numberPos = payload.find(":", viewIdPos + 6);
if (numberPos == std::string::npos)
return 0;
for (++numberPos; numberPos < payload.length(); ++numberPos)
{
if (payload[numberPos] == ',' || payload[numberPos] == '}' || (payload[numberPos] >= '0' && payload[numberPos] <= '9'))
break;
}
if (numberPos < payload.length() && payload[numberPos] >= '0' && payload[numberPos] <= '9')
return std::stoi(payload.substr(numberPos));
return 0;
} }
} // end anonymous namespace } // end anonymous namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment