[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - desktop/inc desktop/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Mar 5 09:35:01 UTC 2019
desktop/inc/lib/init.hxx | 8 +++-
desktop/source/lib/init.cxx | 78 +++++++++++++++++++++++++++-----------------
2 files changed, 55 insertions(+), 31 deletions(-)
New commits:
commit b27990077a219b3640e51a31c7d5bd750d792895
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Thu Feb 14 10:52:33 2019 -0500
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Tue Mar 5 10:34:38 2019 +0100
LOK: Cache JSON payloads
Change-Id: I81f74027363d4b2959c053057851cf01fc94af8b
Reviewed-on: https://gerrit.libreoffice.org/68269
Reviewed-by: Andras Timar <andras.timar at collabora.com>
Tested-by: Andras Timar <andras.timar at collabora.com>
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 66696757292a..f2f6f5399649 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -104,10 +104,16 @@ namespace desktop {
RectangleAndPart& setRectangleAndPart(const std::string& payload);
/// Return the parsed RectangleAndPart instance.
const RectangleAndPart& getRectangleAndPart() const;
+ /// Parse and set the JSON object and return it. Clobbers PayloadString.
+ boost::property_tree::ptree& setJson(const std::string& payload);
+ /// Set a Json object and update PayloadString.
+ void setJson(const boost::property_tree::ptree& rTree);
+ /// Return the parsed JSON instance.
+ const boost::property_tree::ptree& getJson() const;
int Type;
std::string PayloadString;
- boost::variant<boost::blank, RectangleAndPart> PayloadObject;
+ boost::variant<boost::blank, RectangleAndPart, boost::property_tree::ptree> PayloadObject;
};
typedef std::vector<CallbackData> queue_type;
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index b216928c0db3..59d4f36aebc0 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -28,6 +28,7 @@
#include <memory>
#include <iostream>
#include <boost/property_tree/json_parser.hpp>
+#include <boost/algorithm/string.hpp>
#include <LibreOfficeKit/LibreOfficeKit.h>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -469,6 +470,33 @@ const RectangleAndPart& CallbackFlushHandler::CallbackData::getRectangleAndPart(
return boost::get<RectangleAndPart>(PayloadObject);
}
+boost::property_tree::ptree& CallbackFlushHandler::CallbackData::setJson(const std::string& payload)
+{
+ boost::property_tree::ptree aTree;
+ std::stringstream aStream(payload);
+ boost::property_tree::read_json(aStream, aTree);
+
+ // Let boost normalize the payload so it always matches the cache.
+ setJson(aTree);
+
+ return boost::get<boost::property_tree::ptree>(PayloadObject);
+}
+
+void CallbackFlushHandler::CallbackData::setJson(const boost::property_tree::ptree& rTree)
+{
+ std::stringstream aJSONStream;
+ constexpr bool bPretty = false; // Don't waste time and bloat logs.
+ boost::property_tree::write_json(aJSONStream, rTree, bPretty);
+ PayloadString = boost::trim_copy(aJSONStream.str());
+
+ PayloadObject = rTree;
+}
+
+const boost::property_tree::ptree& CallbackFlushHandler::CallbackData::getJson() const
+{
+ return boost::get<boost::property_tree::ptree>(PayloadObject);
+}
+
}
namespace {
@@ -1158,9 +1186,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
case LOK_CALLBACK_WINDOW:
{
// reading JSON by boost might be slow?
- boost::property_tree::ptree aTree;
- std::stringstream aStream(payload);
- boost::property_tree::read_json(aStream, aTree);
+ boost::property_tree::ptree& aTree = aCallbackData.setJson(payload);
const unsigned nLOKWindowId = aTree.get<unsigned>("id", 0);
if (aTree.get<std::string>("action", "") == "invalidate")
{
@@ -1172,9 +1198,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
removeAll([&nLOKWindowId] (const queue_type::value_type& elem) {
if (elem.Type == LOK_CALLBACK_WINDOW)
{
- boost::property_tree::ptree aOldTree;
- std::stringstream aOldStream(elem.PayloadString);
- boost::property_tree::read_json(aOldStream, aOldTree);
+ const boost::property_tree::ptree& aOldTree = elem.getJson();
const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0);
if (aOldTree.get<std::string>("action", "") == "invalidate" &&
nLOKWindowId == nOldDialogId)
@@ -1189,24 +1213,22 @@ void CallbackFlushHandler::queue(const int type, const char* data)
{
// if we have to invalidate all of the window, ignore
// any part invalidation message
- const auto& pos = std::find_if(m_queue.rbegin(), m_queue.rend(),
- [&nLOKWindowId] (const queue_type::value_type& elem)
- {
- if (elem.Type != LOK_CALLBACK_WINDOW)
- return false;
-
- boost::property_tree::ptree aOldTree;
- std::stringstream aOldStream(elem.PayloadString);
- boost::property_tree::read_json(aOldStream, aOldTree);
- const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0);
- if (aOldTree.get<std::string>("action", "") == "invalidate" &&
- nLOKWindowId == nOldDialogId &&
- aOldTree.get<std::string>("rectangle", "").empty())
- {
- return true;
- }
- return false;
- });
+ const auto& pos = std::find_if(
+ m_queue.rbegin(), m_queue.rend(),
+ [&nLOKWindowId](const queue_type::value_type& elem) {
+ if (elem.Type != LOK_CALLBACK_WINDOW)
+ return false;
+
+ const boost::property_tree::ptree& aOldTree = elem.getJson();
+ const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0);
+ if (aOldTree.get<std::string>("action", "") == "invalidate"
+ && nLOKWindowId == nOldDialogId
+ && aOldTree.get<std::string>("rectangle", "").empty())
+ {
+ return true;
+ }
+ return false;
+ });
// we found a invalidate-all window callback
if (pos != m_queue.rend())
@@ -1225,9 +1247,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
if (elem.Type != LOK_CALLBACK_WINDOW)
return false;
- boost::property_tree::ptree aOldTree;
- std::stringstream aOldStream(elem.PayloadString);
- boost::property_tree::read_json(aOldStream, aOldTree);
+ const boost::property_tree::ptree& aOldTree = elem.getJson();
if (aOldTree.get<std::string>("action", "") == "invalidate")
{
const unsigned nOldDialogId = aOldTree.get<unsigned>("id", 0);
@@ -1280,9 +1300,7 @@ void CallbackFlushHandler::queue(const int type, const char* data)
}
aTree.put("rectangle", aNewRect.toString().getStr());
- std::stringstream aJSONStream;
- boost::property_tree::write_json(aJSONStream, aTree);
- payload = aJSONStream.str();
+ aCallbackData.setJson(aTree);
}
}
}
More information about the Libreoffice-commits
mailing list