summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2017-01-31 17:33:49 +0100
committerAndras Timar <andras.timar@collabora.com>2017-02-18 01:05:00 +0100
commit1951d7b2961fc8b48c17a9a30d7c2489857e4dc7 (patch)
treef2e347383985f7325c589afe6566169a7cec7594 /desktop
parent8f13d1ebe42dfea233df3b802202b91cfa82a11c (diff)
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 (cherry picked from commit 20910ea89efb01406e35e9d942613123f78b637f)
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx24
1 files changed, 20 insertions, 4 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 83c872c32433..a62b7770e055 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -446,10 +446,26 @@ bool lcl_isViewCallbackType(const int type)
int lcl_getViewId(const std::string& payload)
{
- boost::property_tree::ptree aTree;
- std::stringstream aStream(payload);
- boost::property_tree::read_json(aStream, aTree);
- return aTree.get<int>("viewId");
+ // this is a cheap way how to get the viewId from a JSON message; proper
+ // parsing is terribly expensive, and we just need the viewId here
+ size_t viewIdPos = payload.find("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