sal/rtl/strtmpl.hxx | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-)
New commits: commit c95d2c8ef7a7d062536e225b843006bdf3d7d65b Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Feb 22 16:51:09 2022 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Feb 23 06:00:22 2022 +0100 Deduplicate shortenedCompare*_WithLength Change-Id: Ie1ba2787036955976f43217e64af889a314a2e65 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130325 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> 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)); } /* ----------------------------------------------------------------------- */