Hello,

>     template < typename DstType, typename SrcType > 
>     ::com::sun::star::uno::Sequence< DstType > arrayToSequence( const 
> SrcType* i_pArray, sal_Int32 nNum )
>     {
>         ::com::sun::star::uno::Sequence< DstType > result( nNum );
>         ::std::copy( i_pArray, i_pArray+nNum, result.getArray() );
>         return result;
>     }

If DstType and SrcType refer to the same type (which is often the case),
using one of Sequence's ctors is faster, i.e.

::com::sun::star::uno::Sequence<DstType> seq( pArray, nElements );

Adding a "special"

    template <typename T>
    inline ::com::sun::star::uno::Sequence<T> arrayToSequence(
        T const* p, sal_Int32 n )
    {
        return ::com::sun::star::uno::Sequence<T>(p, n);
    }

would most probably break existing code which has explicitly specified
DstType (=> leads to ambiguity when DstType equals SrcType).  So I
recommend to use that Sequence ctor directly whenever possible.

>     template < typename DstType, typename SrcType > 
>     ::com::sun::star::uno::Sequence< DstType > containerToSequence( const 
> SrcType& i_Container )
>     {
>         ::com::sun::star::uno::Sequence< DstType > result( i_Container.size() 
> );
>         ::std::copy( i_Container.begin(), i_Container.end(), 
> result.getArray() );
>         return result;
>     }

The same optimization applies when copying from a std::vector; can
seamlessly be overloaded by adding

    template <typename T>
    inline ::com::sun::star::uno::Sequence<T> containerToSequence(
        ::std::vector<T> const& v )
    {
        return ::com::sun::star::uno::Sequence<T>( &v[0], v.size() );
    }

(No need to explicitly state the element type.)

I will add the latter function to comphelper/sequence.hxx if nobody
(incl. any compiler) complains.

regards,
-Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to