[Libreoffice-commits] core.git: include/comphelper

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Mar 1 20:27:35 UTC 2019


 include/comphelper/sequence.hxx |   41 ++++++----------------------------------
 1 file changed, 7 insertions(+), 34 deletions(-)

New commits:
commit 289cff91eb67c27874ba11115b9188a05ea8768d
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Mar 1 11:33:28 2019 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Mar 1 21:27:10 2019 +0100

    Use parameter pack + folding to have only one concatSequences
    
    Change-Id: I4a303f8aab7a0e2af83dd9be7c269dc6855311a9
    Reviewed-on: https://gerrit.libreoffice.org/68542
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/comphelper/sequence.hxx b/include/comphelper/sequence.hxx
index d80534f4a8c7..59cd74fb1b83 100644
--- a/include/comphelper/sequence.hxx
+++ b/include/comphelper/sequence.hxx
@@ -43,21 +43,15 @@ namespace comphelper
         }
     }
 
-    /// concat two sequences
-    template <class T>
-    inline css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& _rLeft, const css::uno::Sequence<T>& _rRight)
+    /// concat several sequences
+    template <class T, class... Ss>
+    inline css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& rS1, const Ss&... rSn)
     {
-        sal_Int32 nLeft(_rLeft.getLength()), nRight(_rRight.getLength());
-        const T* pLeft = _rLeft.getConstArray();
-        const T* pRight = _rRight.getConstArray();
-
-        sal_Int32 nReturnLen(nLeft + nRight);
-        css::uno::Sequence<T> aReturn(nReturnLen);
+        // unary fold to disallow empty parameter pack: at least have one sequence in rSn
+        css::uno::Sequence<T> aReturn(rS1.getLength() + (... + rSn.getLength()));
         T* pReturn = aReturn.getArray();
-
-        internal::implCopySequence(pLeft, pReturn, nLeft);
-        internal::implCopySequence(pRight, pReturn, nRight);
-
+        (internal::implCopySequence(rS1.getConstArray(), pReturn, rS1.getLength()), ...,
+         internal::implCopySequence(rSn.getConstArray(), pReturn, rSn.getLength()));
         return aReturn;
     }
 
@@ -89,27 +83,6 @@ namespace comphelper
         return ret;
     }
 
-    /// concat three sequences
-    template <class T>
-    inline css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& _rLeft, const css::uno::Sequence<T>& _rMiddle, const css::uno::Sequence<T>& _rRight)
-    {
-        sal_Int32 nLeft(_rLeft.getLength()), nMiddle(_rMiddle.getLength()), nRight(_rRight.getLength());
-        const T* pLeft = _rLeft.getConstArray();
-        const T* pMiddle = _rMiddle.getConstArray();
-        const T* pRight = _rRight.getConstArray();
-
-        sal_Int32 nReturnLen(nLeft + nMiddle + nRight);
-        css::uno::Sequence<T> aReturn(nReturnLen);
-        T* pReturn = aReturn.getArray();
-
-        internal::implCopySequence(pLeft, pReturn, nLeft);
-        internal::implCopySequence(pMiddle, pReturn, nMiddle);
-        internal::implCopySequence(pRight, pReturn, nRight);
-
-        return aReturn;
-    }
-
-
     /// remove a specified element from a sequences
     template<class T>
     inline void removeElementAt(css::uno::Sequence<T>& _rSeq, sal_Int32 _nPos)


More information about the Libreoffice-commits mailing list