Date: prev next · Thread: first prev next last
2015 Archives by date, by thread · List index


On 02/23/2015 06:02 PM, Bjoern Michaelsen wrote:
commit f9632ab04288909c9ff4de56171c31acb7f2c573
Author: Bjoern Michaelsen <bjoern.michaelsen@canonical.com>
Date:   Mon Feb 23 02:38:18 2015 +0100

     use init lists for property sequences

     Change-Id: I8b3b2b839c37b584e1a4036e49af7ff2737ea7f6

[...]
diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx
new file mode 100644
index 0000000..ce28e4f
--- /dev/null
+++ b/include/comphelper/propertysequence.hxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX
+#define INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX
+
+#include <utility>
+#include <initializer_list>
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+namespace comphelper
+{
+    ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > InitPropertySequence(
+        ::std::initializer_list< ::std::pair< OUString, ::com::sun::star::uno::Any > > vInit)
+    {
+        ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue> 
vResult{static_cast<sal_Int32>(vInit.size())};
+        size_t nCount{0};
+        for(auto aEntry : vInit)
+        {
+            vResult[nCount].Name = std::move(aEntry.first);
+            vResult[nCount].Value = std::move(aEntry.second);

Rather than allowing to move out of the temporary pair, better avoid its creation in the first place:

           for(auto const & aEntry : vInit)

+            ++nCount;
+        }
+        return std::move(vResult);

That use of std::move is actually a pessimization, as it prevents RVO.

+    }
+}   // namespace comphelper
+
+
+
+#endif // INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.