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 7b2ea917cecbaa7deb67559fe09531bb2a3d98eb
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Oct 21 19:56:59 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Oct 21 20:28:43 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>

diff --git a/comphelper/qa/unit/propertyvalue.cxx 
b/comphelper/qa/unit/propertyvalue.cxx
index 877a964478ac..4523bb49d352 100644
--- a/comphelper/qa/unit/propertyvalue.cxx
+++ b/comphelper/qa/unit/propertyvalue.cxx
@@ -103,7 +103,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(u"FieldType"_ustr, aFirst.Name);
diff --git a/comphelper/source/misc/sequenceashashmap.cxx 
b/comphelper/source/misc/sequenceashashmap.cxx
index ba4955e09780..9f8655f3d164 100644
--- a/comphelper/source/misc/sequenceashashmap.cxx
+++ b/comphelper/source/misc/sequenceashashmap.cxx
@@ -302,13 +302,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", "");
@@ -364,10 +361,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")
         {
@@ -375,10 +369,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);
         }
@@ -389,6 +380,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 555c5f5aea78..92bfadd363e9 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, u".uno:SetDocumentProperties"_ustr, aArgs);
 
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 28a31a50ed28..b6e071d782d4 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -543,7 +543,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
         ]
     }
 }
-)json"_ostr);
+)json");
     uno::Sequence<beans::PropertyValue> aArgs = 
comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:UpdateBookmarks"_ustr, aArgs);
 
@@ -829,7 +829,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateRefmarks)
         ]
     }
 }
-)json"_ostr);
+)json");
     aArgs = comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:UpdateFields"_ustr, aArgs);
 
@@ -887,7 +887,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateFieldmark)
         }
     }
 }
-)json"_ostr);
+)json");
     aArgs = comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:UpdateTextFormField"_ustr, aArgs);
 
@@ -938,7 +938,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateSections)
         ]
     }
 }
-)json"_ostr);
+)json");
     aArgs = comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:UpdateSections"_ustr, aArgs);
 
@@ -1035,7 +1035,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmark)
         }
     }
 }
-)json"_ostr);
+)json");
     uno::Sequence<beans::PropertyValue> aArgs = 
comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:UpdateBookmark"_ustr, aArgs);
 
@@ -1089,7 +1089,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateRefmark)
         }
     }
 }
-)json"_ostr);
+)json");
     aArgs = comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:UpdateField"_ustr, aArgs);
 
@@ -1127,7 +1127,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testDeleteBookmarks)
         "value": "ZOTERO_BREF_"
     }
 }
-)json"_ostr);
+)json");
     uno::Sequence<beans::PropertyValue> aArgs = 
comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:DeleteBookmarks"_ustr, aArgs);
 
@@ -1164,7 +1164,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testDeleteFields)
         "value": "ZOTERO_ITEM CSL_CITATION"
     }
 }
-)json"_ostr);
+)json");
     aArgs = comphelper::containerToSequence(aArgsVec);
     dispatchCommand(mxComponent, u".uno:DeleteFields"_ustr, aArgs);
 
diff --git a/sw/qa/uibase/shells/textsh.cxx b/sw/qa/uibase/shells/textsh.cxx
index 265ac4c7dff1..3721569977f0 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, u".uno:DeleteSections"_ustr, aArgs);
 

Reply via email to