summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2023-04-14 11:34:13 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2023-04-14 13:33:46 +0200
commit43b893f3a1812b1ca4380267e78ff1b846c41436 (patch)
tree287839948960ea8b4088afb5d262a47d3aa618dc /include/o3tl
parentb1c88800c2e3e6a509ba08050c7e65ce7d0e693a (diff)
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.kaganski@collabora.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/string_view.hxx16
1 files changed, 8 insertions, 8 deletions
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"