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

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 11 16:37:17 UTC 2019


 include/comphelper/sequence.hxx |   22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

New commits:
commit 753e9592e5fe6cfd8f437d0049b9604d1e414a14
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Aug 11 17:49:31 2019 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Aug 11 18:36:16 2019 +0200

    Use standard algorithms instead of custom copy function
    
    Change-Id: If0e3233590b31558dd0f28ff361461f2c5de5697
    Reviewed-on: https://gerrit.libreoffice.org/77270
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/comphelper/sequence.hxx b/include/comphelper/sequence.hxx
index a9cd6f137fd5..3c448cd6573a 100644
--- a/include/comphelper/sequence.hxx
+++ b/include/comphelper/sequence.hxx
@@ -24,6 +24,7 @@
 #include <osl/diagnose.h>
 #include <comphelper/comphelperdllapi.h>
 
+#include <algorithm>
 #include <vector>
 
 namespace comphelper
@@ -33,25 +34,15 @@ namespace comphelper
     */
     COMPHELPER_DLLPUBLIC sal_Int32 findValue(const css::uno::Sequence< OUString >& _rList, const OUString& _rValue);
 
-    namespace internal
-    {
-        template <class T>
-        inline void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen)
-        {
-            for (sal_Int32 i=0; i<_nSourceLen; ++i, ++_pSource, ++_pDest)
-                *_pDest = *_pSource;
-        }
-    }
-
     /// concat several sequences
     template <class T, class... Ss>
     inline css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& rS1, const Ss&... rSn)
     {
         // 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(rS1.getConstArray(), pReturn, rS1.getLength()), ...,
-         internal::implCopySequence(rSn.getConstArray(), pReturn, rSn.getLength()));
+        T* pReturn;
+        ((pReturn = std::copy_n(rS1.getConstArray(), rS1.getLength(), aReturn.getArray())), ...,
+         (pReturn = std::copy_n(rSn.getConstArray(), rSn.getLength(), pReturn)));
         return aReturn;
     }
 
@@ -64,8 +55,7 @@ namespace comphelper
         sal_Int32 n1 = left.getLength();
         css::uno::Sequence<T> ret(n1 + right.getLength());
             //TODO: check for overflow
-        T * p = ret.getArray();
-        internal::implCopySequence(left.getConstArray(), p, n1);
+        std::copy_n(left.getConstArray(), n1, ret.getArray());
         sal_Int32 n2 = n1;
         for (sal_Int32 i = 0; i != right.getLength(); ++i) {
             bool found = false;
@@ -92,7 +82,7 @@ namespace comphelper
         OSL_ENSURE(0 <= _nPos && _nPos < nLength, "invalid index");
 
         T* pPos = _rSeq.getArray() + _nPos;
-        internal::implCopySequence(pPos + 1, pPos, nLength - _nPos - 1);
+        std::move(pPos + 1, pPos + nLength - _nPos, pPos);
 
         _rSeq.realloc(nLength-1);
     }


More information about the Libreoffice-commits mailing list