1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 11:53:53 +00:00

Reduce the call to tolower() for each character when the string is already in lower case.

- only a minor performance gain according to the MSVC profiler
This commit is contained in:
cc9cii 2015-12-19 18:50:07 +11:00
parent abe6904a94
commit 90b76801f6
2 changed files with 16 additions and 1 deletions

View file

@ -106,10 +106,11 @@ int CSMWorld::InfoCollection::getInfoIndex (const std::string& id, const std::st
return -1;
// brute force loop
std::string lowerId = Misc::StringUtils::lowerCase (id);
for (std::vector<std::pair<std::string, int> >::const_iterator it = iter->second.begin();
it != iter->second.end(); ++it)
{
if (Misc::StringUtils::ciEqual(it->first, id))
if (Misc::StringUtils::cEqual(it->first, lowerId))
return it->second;
}

View file

@ -35,6 +35,20 @@ public:
return true;
}
static bool cEqual(const std::string &x, const std::string &y) {
if (x.size() != y.size()) {
return false;
}
std::string::const_iterator xit = x.begin();
std::string::const_iterator yit = y.begin();
for (; xit != x.end(); ++xit, ++yit) {
if (*xit != *yit) {
return false;
}
}
return true;
}
static int ciCompareLen(const std::string &x, const std::string &y, size_t len)
{
std::string::const_iterator xit = x.begin();