mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
Avoid redundant allocations in Store::search
This commit is contained in:
parent
6e996bf2a3
commit
25ca89b560
1 changed files with 6 additions and 8 deletions
|
@ -136,15 +136,14 @@ namespace MWWorld
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T *Store<T>::search(const std::string &id) const
|
const T *Store<T>::search(const std::string &id) const
|
||||||
{
|
{
|
||||||
T item;
|
std::string idLower = Misc::StringUtils::lowerCase(id);
|
||||||
item.mId = 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()) {
|
if (dit != mDynamic.end()) {
|
||||||
return &dit->second;
|
return &dit->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
typename std::map<std::string, T>::const_iterator it = mStatic.find(item.mId);
|
typename std::map<std::string, T>::const_iterator it = mStatic.find(idLower);
|
||||||
|
|
||||||
if (it != mStatic.end() && Misc::StringUtils::ciEqual(it->second.mId, id)) {
|
if (it != mStatic.end() && Misc::StringUtils::ciEqual(it->second.mId, id)) {
|
||||||
return &(it->second);
|
return &(it->second);
|
||||||
|
@ -274,10 +273,9 @@ namespace MWWorld
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Store<T>::eraseStatic(const std::string &id)
|
bool Store<T>::eraseStatic(const std::string &id)
|
||||||
{
|
{
|
||||||
T item;
|
std::string idLower = Misc::StringUtils::lowerCase(id);
|
||||||
item.mId = Misc::StringUtils::lowerCase(id);
|
|
||||||
|
|
||||||
typename std::map<std::string, T>::iterator it = mStatic.find(item.mId);
|
typename std::map<std::string, T>::iterator it = mStatic.find(idLower);
|
||||||
|
|
||||||
if (it != mStatic.end() && Misc::StringUtils::ciEqual(it->second.mId, id)) {
|
if (it != mStatic.end() && Misc::StringUtils::ciEqual(it->second.mId, id)) {
|
||||||
// delete from the static part of mShared
|
// delete from the static part of mShared
|
||||||
|
@ -285,7 +283,7 @@ namespace MWWorld
|
||||||
typename std::vector<T *>::iterator end = sharedIter + mStatic.size();
|
typename std::vector<T *>::iterator end = sharedIter + mStatic.size();
|
||||||
|
|
||||||
while (sharedIter != mShared.end() && sharedIter != end) {
|
while (sharedIter != mShared.end() && sharedIter != end) {
|
||||||
if((*sharedIter)->mId == item.mId) {
|
if((*sharedIter)->mId == idLower) {
|
||||||
mShared.erase(sharedIter);
|
mShared.erase(sharedIter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue