From 25ca89b56098e2c117e9ccf64796b744a48a081a Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 23 Feb 2017 17:18:27 +0100 Subject: [PATCH] Avoid redundant allocations in Store::search --- apps/openmw/mwworld/store.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 9221448141..cdf66f5708 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -136,15 +136,14 @@ namespace MWWorld template const T *Store::search(const std::string &id) const { - T item; - item.mId = Misc::StringUtils::lowerCase(id); + std::string idLower = Misc::StringUtils::lowerCase(id); - typename Dynamic::const_iterator dit = mDynamic.find(item.mId); + typename Dynamic::const_iterator dit = mDynamic.find(idLower); if (dit != mDynamic.end()) { return &dit->second; } - typename std::map::const_iterator it = mStatic.find(item.mId); + typename std::map::const_iterator it = mStatic.find(idLower); if (it != mStatic.end() && Misc::StringUtils::ciEqual(it->second.mId, id)) { return &(it->second); @@ -274,10 +273,9 @@ namespace MWWorld template bool Store::eraseStatic(const std::string &id) { - T item; - item.mId = Misc::StringUtils::lowerCase(id); + std::string idLower = Misc::StringUtils::lowerCase(id); - typename std::map::iterator it = mStatic.find(item.mId); + typename std::map::iterator it = mStatic.find(idLower); if (it != mStatic.end() && Misc::StringUtils::ciEqual(it->second.mId, id)) { // delete from the static part of mShared @@ -285,7 +283,7 @@ namespace MWWorld typename std::vector::iterator end = sharedIter + mStatic.size(); while (sharedIter != mShared.end() && sharedIter != end) { - if((*sharedIter)->mId == item.mId) { + if((*sharedIter)->mId == idLower) { mShared.erase(sharedIter); break; }