include/comphelper/propertysequence.hxx | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)
New commits: commit 4a8d3b80283cec4a93dd697eab70afcb82f04f4f Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Dec 12 09:24:25 2019 +0100 Commit: Mike Kaganski <mike.kagan...@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.kagan...@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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits