diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-12 09:24:25 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-12 10:21:37 +0100 |
commit | 4a8d3b80283cec4a93dd697eab70afcb82f04f4f (patch) | |
tree | f5f39a97b96b5e483a5f8fa1523c68085c1a3ec4 /include/comphelper | |
parent | 3fb00763c6b52dd0b63eb572eba206513300ae88 (diff) |
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@collabora.com>
Diffstat (limited to 'include/comphelper')
-rw-r--r-- | include/comphelper/propertysequence.hxx | 27 |
1 files changed, 12 insertions, 15 deletions
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 |