include/o3tl/string_view.hxx |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

New commits:
commit 43b893f3a1812b1ca4380267e78ff1b846c41436
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Apr 14 11:34:13 2023 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Apr 14 13:33:46 2023 +0200

    Another micro-optimization
    
    I was surprised to see that all three major compilers generate
    better code using the pointer arithmetics compared to indices.
    
    Change-Id: I934a840a43159babf51f337b4af7f972424ff4fb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150323
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx
index 36b786e534e2..6084b5692cb5 100644
--- a/include/o3tl/string_view.hxx
+++ b/include/o3tl/string_view.hxx
@@ -433,20 +433,20 @@ inline bool implIsWhitespace(sal_Unicode c)
 template <typename charT, typename traits = std::char_traits<charT>>
 std::basic_string_view<charT, traits> trim(std::basic_string_view<charT, 
traits> str)
 {
-    size_t nFirst = 0;
-    size_t nLast = str.size();
+    auto pFirst = str.data();
+    auto pLast = pFirst + str.size();
 
-    while ((nFirst < nLast) && internal::implIsWhitespace(str.data()[nFirst]))
-        ++nFirst;
+    while ((pFirst < pLast) && internal::implIsWhitespace(*pFirst))
+        ++pFirst;
 
-    if (nFirst == nLast)
+    if (pFirst == pLast)
         return {};
 
     do
-        --nLast;
-    while (internal::implIsWhitespace(str.data()[nLast]));
+        --pLast;
+    while (internal::implIsWhitespace(*pLast));
 
-    return { str.data() + nFirst, nLast - nFirst + 1 };
+    return std::basic_string_view<charT, traits>(pFirst, pLast - pFirst + 1);
 }
 
 // "deduction guides"

Reply via email to