diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-04-10 17:00:06 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-04-10 22:10:02 +0200 |
commit | 5a11edc795d8a3ef1e15fc4e251f594911403131 (patch) | |
tree | af4770b52b10f9c72d6f5fd05bf55f91cf4427ca /sal | |
parent | 3748fe3e4fc22a400b3120010192b75754e38b17 (diff) |
use std lib for sal_Unicode version of indexOfChar_WithLength
if possible, which will probably have a better word-at-a-time
algorithm.
Change-Id: Ia338a0aad81ef450d482701139f131d6d577b737
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113922
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/strtmpl.hxx | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx index a2677f7da0f2..d0f853f62feb 100644 --- a/sal/rtl/strtmpl.hxx +++ b/sal/rtl/strtmpl.hxx @@ -398,6 +398,14 @@ sal_Int32 indexOfChar_WithLength ( const IMPL_RTL_ST IMPL_RTL_STRCODE* p = static_cast<IMPL_RTL_STRCODE*>(std::memchr(const_cast<IMPL_RTL_STRCODE *>(pStr), c, nLen)); return p ? p - pStr : -1; } + else if constexpr (sizeof(IMPL_RTL_STRCODE) == sizeof(char16_t)) + { + // take advantage of builtin optimisations + if (nLen <= 0) // char_traits::find takes an unsigned length + return -1; + char16_t const * p = std::char_traits<char16_t>::find(pStr, nLen, c); + return p ? p - pStr : -1; + } else { const IMPL_RTL_STRCODE* pTempStr = pStr; @@ -409,7 +417,6 @@ sal_Int32 indexOfChar_WithLength ( const IMPL_RTL_ST pTempStr++; nLen--; } - return -1; } } |