[Libreoffice-commits] core.git: desktop/source
Marco Cecchetti (via logerrit)
logerrit at kemper.freedesktop.org
Fri Aug 20 12:17:37 UTC 2021
desktop/source/lib/init.cxx | 79 +++++++++++++++++---------------------------
1 file changed, 31 insertions(+), 48 deletions(-)
New commits:
commit 46d3fdeb4fa35e0575395a3a91213fd81fda0e50
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Wed Aug 18 12:29:01 2021 +0200
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Aug 20 14:16:53 2021 +0200
go on switching from boost::property_tree to JsonWriter
JsonWriter provides better performance than boost::property_tree and
it is also cleaner, so we need to start using the latter in place of
the former as much as possible.
Change-Id: I8c1e910c0b3d511b89679e622e2cc5d4848a8b47
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120656
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 916f2cc9ea14..da8c0d5a1595 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -482,37 +482,31 @@ std::vector<beans::PropertyValue> desktop::jsonToPropertyValuesVector(const char
return aArguments;
}
-
-static boost::property_tree::ptree unoAnyToPropertyTree(const uno::Any& anyItem)
+static void unoAnyToJson(tools::JsonWriter& rJson, const char * pNodeName, const uno::Any& anyItem)
{
- boost::property_tree::ptree aTree;
+ auto aNode = rJson.startNode(pNodeName);
OUString aType = anyItem.getValueTypeName();
- aTree.put("type", aType.toUtf8().getStr());
+ rJson.put("type", aType.toUtf8().getStr());
if (aType == "string")
- aTree.put("value", anyItem.get<OUString>().toUtf8().getStr());
+ rJson.put("value", anyItem.get<OUString>().toUtf8().getStr());
else if (aType == "unsigned long")
- aTree.put("value", OString::number(anyItem.get<sal_uInt32>()).getStr());
+ rJson.put("value", OString::number(anyItem.get<sal_uInt32>()).getStr());
else if (aType == "long")
- aTree.put("value", OString::number(anyItem.get<sal_Int32>()).getStr());
+ rJson.put("value", OString::number(anyItem.get<sal_Int32>()).getStr());
else if (aType == "[]any")
{
uno::Sequence<uno::Any> aSeq;
if (anyItem >>= aSeq)
{
- boost::property_tree::ptree aSubTree;
+ auto valueNode = rJson.startNode("value");
for (auto i = 0; i < aSeq.getLength(); ++i)
{
- aSubTree.add_child(OString::number(i).getStr(), unoAnyToPropertyTree(aSeq[i]));
+ unoAnyToJson(rJson, OString::number(i).getStr(), aSeq[i]);
}
- aTree.add_child("value", aSubTree);
}
}
-
- // TODO: Add more as required
-
- return aTree;
}
namespace desktop {
@@ -3775,21 +3769,17 @@ public:
virtual void SAL_CALL dispatchFinished(const css::frame::DispatchResultEvent& rEvent) override
{
- boost::property_tree::ptree aTree;
- aTree.put("commandName", maCommand.getStr());
+ tools::JsonWriter aJson;
+ aJson.put("commandName", maCommand);
if (rEvent.State != frame::DispatchResultState::DONTKNOW)
{
bool bSuccess = (rEvent.State == frame::DispatchResultState::SUCCESS);
- aTree.put("success", bSuccess);
+ aJson.put("success", bSuccess);
}
- aTree.add_child("result", unoAnyToPropertyTree(rEvent.Result));
-
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- OString aPayload = aStream.str().c_str();
- mpCallback->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aPayload.getStr());
+ unoAnyToJson(aJson, "result", rEvent.Result);
+ mpCallback->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
}
virtual void SAL_CALL disposing(const css::lang::EventObject&) override {}
@@ -3917,13 +3907,10 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
bool bResult = doc_saveAs(pThis, aURLUtf8.getStr(), "pdf", nullptr);
// Send the result of save
- boost::property_tree::ptree aTree;
- aTree.put("commandName", pCommand);
- aTree.put("success", bResult);
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- OString aPayload = aStream.str().c_str();
- pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aPayload.getStr());
+ tools::JsonWriter aJson;
+ aJson.put("commandName", pCommand);
+ aJson.put("success", bResult);
+ pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
return;
}
@@ -3952,18 +3939,16 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
// skip saving and tell the result via UNO_COMMAND_RESULT
if (bDontSaveIfUnmodified && !pDocSh->IsModified())
{
- boost::property_tree::ptree aTree;
- aTree.put("commandName", pCommand);
- aTree.put("success", false);
-
+ tools::JsonWriter aJson;
+ aJson.put("commandName", pCommand);
+ aJson.put("success", false);
// Add the reason for not saving
- const uno::Any aResultValue = uno::makeAny(OUString("unmodified"));
- aTree.add_child("result", unoAnyToPropertyTree(aResultValue));
-
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- OString aPayload = aStream.str().c_str();
- pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aPayload.getStr());
+ {
+ auto resultNode = aJson.startNode("result");
+ aJson.put("type", "string");
+ aJson.put("value", "unmodified");
+ }
+ pDocument->mpCallbackFlushHandlers[nView]->queue(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
return;
}
}
@@ -5833,7 +5818,7 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
uno::Reference<container::XNameAccess> xTypeDetection(xSFactory->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
const uno::Sequence<OUString> aTypes = xTypeDetection->getElementNames();
- boost::property_tree::ptree aTree;
+ tools::JsonWriter aJson;
for (const OUString& rType : aTypes)
{
uno::Sequence<beans::PropertyValue> aValues;
@@ -5843,15 +5828,13 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
OUString aValue;
if (it != aValues.end() && (it->Value >>= aValue) && !aValue.isEmpty())
{
- boost::property_tree::ptree aChild;
- aChild.put("MediaType", aValue.toUtf8());
- aTree.add_child(rType.toUtf8().getStr(), aChild);
+ auto typeNode = aJson.startNode(rType.toUtf8().getStr());
+ aJson.put("MediaType", aValue.toUtf8());
}
}
}
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- return strdup(aStream.str().c_str());
+
+ return strdup(aJson.extractData());
}
static void lo_setOptionalFeatures(LibreOfficeKit* pThis, unsigned long long const features)
More information about the Libreoffice-commits
mailing list