comphelper/qa/unit/propertyvalue.cxx | 2 +- comphelper/source/misc/sequenceashashmap.cxx | 25 ++++++++++++------------- include/comphelper/propertysequence.hxx | 2 +- sfx2/qa/cppunit/doc.cxx | 2 +- sw/qa/uibase/shells/shells.cxx | 16 ++++++++-------- sw/qa/uibase/shells/textsh.cxx | 2 +- 6 files changed, 24 insertions(+), 25 deletions(-)
New commits: commit e0856bc538fb938af372ea7cd250a05a30025556 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Oct 21 19:56:59 2024 +0500 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Oct 22 09:00:27 2024 +0200 Optimize JsonToPropertyValues a bit 1. Make it take string view: helps to avoid extra string allocation e.g. in desktop::jsonToPropertyValuesVector, and will help more, when C++26 stringstream ctor taking string view is available. 2. Factor out a function taking boost::property_tree::ptree, making implementation simpler for [][]com.sun.star.beans.PropertyValue and []com.sun.star.beans.PropertyValue, without writing a child node to a JSON string, and parsing it again. Change-Id: I16ac2641633ea67a7c9c054c9df09a790500e6fb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175361 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit 7b2ea917cecbaa7deb67559fe09531bb2a3d98eb) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175384 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/comphelper/qa/unit/propertyvalue.cxx b/comphelper/qa/unit/propertyvalue.cxx index a7cb204fc5e2..9c7b59f486d4 100644 --- a/comphelper/qa/unit/propertyvalue.cxx +++ b/comphelper/qa/unit/propertyvalue.cxx @@ -106,7 +106,7 @@ class MakePropertyValueTest : public CppUnit::TestFixture ] } } -)json"_ostr); +)json"); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aRet.size()); beans::PropertyValue aFirst = aRet[0]; CPPUNIT_ASSERT_EQUAL(OUString("FieldType"), aFirst.Name); diff --git a/comphelper/source/misc/sequenceashashmap.cxx b/comphelper/source/misc/sequenceashashmap.cxx index 3c3ae6547ebe..928e8075f3d6 100644 --- a/comphelper/source/misc/sequenceashashmap.cxx +++ b/comphelper/source/misc/sequenceashashmap.cxx @@ -308,13 +308,10 @@ void SequenceAsHashMap::update(const SequenceAsHashMap& rUpdate) } } -std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson) +static std::vector<css::beans::PropertyValue> JsonToPropertyValues(const boost::property_tree::ptree& aTree) { std::vector<beans::PropertyValue> aArguments; - boost::property_tree::ptree aTree, aNodeNull, aNodeValue; - std::stringstream aStream((std::string(rJson))); - boost::property_tree::read_json(aStream, aTree); - + boost::property_tree::ptree aNodeNull, aNodeValue; for (const auto& rPair : aTree) { const std::string& rType = rPair.second.get<std::string>("type", ""); @@ -378,10 +375,7 @@ std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson else if (rType == "[]com.sun.star.beans.PropertyValue") { aNodeValue = rPair.second.get_child("value", aNodeNull); - std::stringstream s; - boost::property_tree::write_json(s, aNodeValue); - std::vector<beans::PropertyValue> aPropertyValues = JsonToPropertyValues(OString(s.str())); - aValue.Value <<= comphelper::containerToSequence(aPropertyValues); + aValue.Value <<= comphelper::containerToSequence(JsonToPropertyValues(aNodeValue)); } else if (rType == "[][]com.sun.star.beans.PropertyValue") { @@ -389,10 +383,7 @@ std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson std::vector<uno::Sequence<beans::PropertyValue>> aSeqs; for (const auto& rItem : aNodeValue) { - std::stringstream s; - boost::property_tree::write_json(s, rItem.second); - std::vector<beans::PropertyValue> aPropertyValues = JsonToPropertyValues(OString(s.str())); - aSeqs.push_back(comphelper::containerToSequence(aPropertyValues)); + aSeqs.push_back(comphelper::containerToSequence(JsonToPropertyValues(rItem.second))); } aValue.Value <<= comphelper::containerToSequence(aSeqs); } @@ -403,6 +394,14 @@ std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson return aArguments; } +std::vector<css::beans::PropertyValue> JsonToPropertyValues(std::string_view rJson) +{ + boost::property_tree::ptree aTree; + std::stringstream aStream((std::string(rJson))); + boost::property_tree::read_json(aStream, aTree); + return JsonToPropertyValues(aTree); +} + } // namespace comphelper /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx index e788f56f428f..787f96f3e855 100644 --- a/include/comphelper/propertysequence.hxx +++ b/include/comphelper/propertysequence.hxx @@ -53,7 +53,7 @@ namespace comphelper return vResult; } - COMPHELPER_DLLPUBLIC std::vector<css::beans::PropertyValue> JsonToPropertyValues(const OString& rJson); + COMPHELPER_DLLPUBLIC std::vector<css::beans::PropertyValue> JsonToPropertyValues(std::string_view rJson); } // namespace comphelper diff --git a/sfx2/qa/cppunit/doc.cxx b/sfx2/qa/cppunit/doc.cxx index 9eea6d29390d..902ac48646e5 100644 --- a/sfx2/qa/cppunit/doc.cxx +++ b/sfx2/qa/cppunit/doc.cxx @@ -126,7 +126,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSetDocumentPropertiesUpdate) } } } -)json"_ostr); +)json"); uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:SetDocumentProperties", aArgs); diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 816498703e43..337dbcd8dee6 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -542,7 +542,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateBookmarks) ] } } -)json"_ostr); +)json"); uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:UpdateBookmarks", aArgs); @@ -946,7 +946,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks) ] } } -)json"_ostr); +)json"); aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:UpdateFields", aArgs); @@ -1004,7 +1004,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateFieldmark) } } } -)json"_ostr); +)json"); aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:UpdateTextFormField", aArgs); @@ -1055,7 +1055,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateSections) ] } } -)json"_ostr); +)json"); aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:UpdateSections", aArgs); @@ -1152,7 +1152,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateBookmark) } } } -)json"_ostr); +)json"); uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:UpdateBookmark", aArgs); @@ -1206,7 +1206,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmark) } } } -)json"_ostr); +)json"); aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:UpdateField", aArgs); @@ -1244,7 +1244,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteBookmarks) "value": "ZOTERO_BREF_" } } -)json"_ostr); +)json"); uno::Sequence<beans::PropertyValue> aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:DeleteBookmarks", aArgs); @@ -1281,7 +1281,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteFields) "value": "ZOTERO_ITEM CSL_CITATION" } } -)json"_ostr); +)json"); aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:DeleteFields", aArgs); diff --git a/sw/qa/uibase/shells/textsh.cxx b/sw/qa/uibase/shells/textsh.cxx index ca72a710df3f..f4c63ad5e8d8 100644 --- a/sw/qa/uibase/shells/textsh.cxx +++ b/sw/qa/uibase/shells/textsh.cxx @@ -56,7 +56,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDeleteSections) "value": "ZOTERO_BIBL" } } -)json"_ostr); +)json"); aArgs = comphelper::containerToSequence(aArgsVec); dispatchCommand(mxComponent, ".uno:DeleteSections", aArgs);