From e66d2aec00a6150d7df39a82db174e2254666fae Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 24 Apr 2026 15:10:37 +0200 Subject: [PATCH] tdf#171853 Use endsWith instead of checking lastIndexOf is at end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There seems to be an idiom used throughout the LibreOffice code where lastIndexOf is called and then the returned index is checked to see if it covers the entire end of the string. This should be equivalent to just calling endsWith but it’s slightly less efficient because lastIndexOf will pointlessly continue searching other places in the string if the end doesn’t match. Change-Id: I4c2c6dd750d41ffabf5d27011c22a4bbb5e32777 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/204300 Reviewed-by: Neil Roberts Tested-by: Jenkins --- scripting/source/provider/URIHelper.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripting/source/provider/URIHelper.cxx b/scripting/source/provider/URIHelper.cxx index f1ed31f47f02..90971103323c 100644 --- a/scripting/source/provider/URIHelper.cxx +++ b/scripting/source/provider/URIHelper.cxx @@ -145,8 +145,7 @@ ScriptingFrameworkURIHelper::initBaseURI() m_xSimpleFileAccess->getFolderContents( uri, true ); auto pChild = std::find_if(children.begin(), children.end(), [&test](const OUString& child) { - sal_Int32 idx = child.lastIndexOf(test); - return idx != -1 && (idx + test.getLength()) == child.getLength(); + return child.endsWith(test); }); if (pChild != children.end()) {