1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 22:34:33 +01:00

Optimise object selection search

* Do case insensitive string matching for object search.
* Return as soon as first field is a hit.
This commit is contained in:
Ted John
2022-07-30 15:50:54 +01:00
committed by GitHub
parent d556eafc73
commit 142b9ff243
3 changed files with 52 additions and 28 deletions

View File

@@ -242,6 +242,26 @@ namespace String
return false;
}
bool Contains(std::string_view haystack, std::string_view needle, bool ignoreCase)
{
if (needle.size() > haystack.size())
return false;
if (!ignoreCase)
return haystack.find(needle) != std::string_view::npos;
auto end = haystack.size() - needle.size();
for (size_t start = 0; start <= end; start++)
{
auto sub = haystack.substr(start, needle.size());
if (Equals(sub, needle, ignoreCase))
{
return true;
}
}
return false;
}
size_t IndexOf(const utf8* str, utf8 match, size_t startIndex)
{
const utf8* ch = str + startIndex;