diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-02-22 16:51:09 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-02-23 06:00:22 +0100 |
commit | c95d2c8ef7a7d062536e225b843006bdf3d7d65b (patch) | |
tree | bdbd4296217d9a396adf2db1139f3f3b628d155b /sal | |
parent | d5c8888dedbf2241f9b09bbb5698f37c89f9510b (diff) |
Deduplicate shortenedCompare*_WithLength
Change-Id: Ie1ba2787036955976f43217e64af889a314a2e65
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130325
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/strtmpl.hxx | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/sal/rtl/strtmpl.hxx b/sal/rtl/strtmpl.hxx index 271f70bc2e37..54a1efd1a555 100644 --- a/sal/rtl/strtmpl.hxx +++ b/sal/rtl/strtmpl.hxx @@ -130,13 +130,8 @@ sal_Int32 shortenedCompare_WithLength ( const IMPL_R sal_Int32 nStr2Len, sal_Int32 nShortenedLength ) { - assert(nStr1Len >= 0); - assert(nStr2Len >= 0); - assert(nShortenedLength >= 0); - // take advantage of builtin optimisations - std::basic_string_view<IMPL_RTL_STRCODE> aView1(pStr1, std::min(nStr1Len, nShortenedLength)); - std::basic_string_view<IMPL_RTL_STRCODE> aView2(pStr2, std::min(nStr2Len, nShortenedLength)); - return aView1.compare(aView2); + return compare_WithLength(pStr1, std::min(nStr1Len, nShortenedLength), + pStr2, std::min(nStr2Len, nShortenedLength)); } /* ----------------------------------------------------------------------- */ @@ -225,27 +220,8 @@ sal_Int32 shortenedCompareIgnoreAsciiCase_WithLength sal_Int32 nStr2Len, sal_Int32 nShortenedLength ) { - assert(nStr1Len >= 0); - assert(nStr2Len >= 0); - assert(nShortenedLength >= 0); - const IMPL_RTL_STRCODE* pStr1End = pStr1 + nStr1Len; - const IMPL_RTL_STRCODE* pStr2End = pStr2 + nStr2Len; - while ( (nShortenedLength > 0) && - (pStr1 < pStr1End) && (pStr2 < pStr2End) ) - { - sal_Int32 nRet = rtl::compareIgnoreAsciiCase( - IMPL_RTL_USTRCODE(*pStr1), IMPL_RTL_USTRCODE(*pStr2)); - if ( nRet != 0 ) - return nRet; - - nShortenedLength--; - pStr1++; - pStr2++; - } - - if ( nShortenedLength <= 0 ) - return 0; - return nStr1Len - nStr2Len; + return compareIgnoreAsciiCase_WithLength(pStr1, std::min(nStr1Len, nShortenedLength), + pStr2, std::min(nStr2Len, nShortenedLength)); } /* ----------------------------------------------------------------------- */ |