[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - desktop/source

Jan Holesovsky kendy at collabora.com
Wed Feb 1 09:50:40 UTC 2017


 desktop/source/lib/init.cxx |   24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

New commits:
commit 9e88c1cb3929392002370aa129f6a17d3c2e12c5
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Jan 31 17:33:49 2017 +0100

    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
    Reviewed-on: https://gerrit.libreoffice.org/33762
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 66608a6..646c77e 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -408,10 +408,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


More information about the Libreoffice-commits mailing list