From 90b76801f6ebe95dba721c2b6ccc997ca43a7593 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sat, 19 Dec 2015 18:50:07 +1100 Subject: [PATCH] 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 --- apps/opencs/model/world/infocollection.cpp | 3 ++- components/misc/stringops.hpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/opencs/model/world/infocollection.cpp b/apps/opencs/model/world/infocollection.cpp index 7b7c274a0..f508b683e 100644 --- a/apps/opencs/model/world/infocollection.cpp +++ b/apps/opencs/model/world/infocollection.cpp @@ -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 >::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; } diff --git a/components/misc/stringops.hpp b/components/misc/stringops.hpp index d6bc19069..1f6da37c7 100644 --- a/components/misc/stringops.hpp +++ b/components/misc/stringops.hpp @@ -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();