tdf#171853 Use endsWith instead of checking lastIndexOf is at end

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 <nroberts@libreoffice.org>
Tested-by: Jenkins
This commit is contained in:
Neil Roberts
2026-04-26 09:32:38 +02:00
parent 961599d662
commit e66d2aec00
+1 -2
View File
@@ -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())
{