[Libreoffice-commits] use init lists for property sequences

Stephan Bergmann sbergman at redhat.com
Mon Feb 23 23:13:56 PST 2015


On 02/23/2015 06:02 PM, Bjoern Michaelsen wrote:
> commit f9632ab04288909c9ff4de56171c31acb7f2c573
> Author: Bjoern Michaelsen <bjoern.michaelsen at 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: */



More information about the LibreOffice mailing list