[Libreoffice-commits] core.git: include/comphelper

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu Dec 12 09:22:48 UTC 2019


 include/comphelper/propertysequence.hxx |   27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

New commits:
commit 4a8d3b80283cec4a93dd697eab70afcb82f04f4f
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Dec 12 09:24:25 2019 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Dec 12 10:21:37 2019 +0100

    Use std::transform instead of for loop
    
    This simplifies the functions, and avoids repeated non-const operator[] on
    sequences, which has significant overhead.
    
    Change-Id: I670c25da6f5422822c931d1f4105b07102d7a3d6
    Reviewed-on: https://gerrit.libreoffice.org/85014
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx
index c384edb2848d..3f9838f9ab8f 100644
--- a/include/comphelper/propertysequence.hxx
+++ b/include/comphelper/propertysequence.hxx
@@ -11,6 +11,7 @@
 #define INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX
 
 #include <utility>
+#include <algorithm>
 #include <initializer_list>
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
@@ -23,15 +24,11 @@ namespace comphelper
         ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
     {
         css::uno::Sequence< css::beans::PropertyValue> vResult{static_cast<sal_Int32>(vInit.size())};
-        size_t nCount{0};
-        for(const auto& aEntry : vInit)
-        {
-            vResult[nCount].Name = aEntry.first;
-            vResult[nCount].Handle = -1;
-            vResult[nCount].Value = aEntry.second;
-            // State is default-initialized to DIRECT_VALUE
-            ++nCount;
-        }
+        std::transform(vInit.begin(), vInit.end(), vResult.begin(),
+                       [](const std::pair<OUString, css::uno::Any>& rInit) {
+                           return css::beans::PropertyValue(rInit.first, -1, rInit.second,
+                                                            css::beans::PropertyState_DIRECT_VALUE);
+                       });
         return vResult;
     }
 
@@ -43,12 +40,12 @@ namespace comphelper
         ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
     {
         css::uno::Sequence<css::uno::Any> vResult{static_cast<sal_Int32>(vInit.size())};
-        size_t nCount{0};
-        for(const auto& aEntry : vInit)
-        {
-            vResult[nCount] <<= css::beans::PropertyValue(aEntry.first, -1, aEntry.second, css::beans::PropertyState_DIRECT_VALUE);
-            ++nCount;
-        }
+        std::transform(vInit.begin(), vInit.end(), vResult.begin(),
+                       [](const std::pair<OUString, css::uno::Any>& rInit) {
+                           return css::uno::Any(
+                               css::beans::PropertyValue(rInit.first, -1, rInit.second,
+                                                         css::beans::PropertyState_DIRECT_VALUE));
+                       });
         return vResult;
     }
 }   // namespace comphelper


More information about the Libreoffice-commits mailing list