From 4e49081ca1f0d658308582ef3084837bb58c33ec Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 19 Oct 2011 22:56:32 +0200 Subject: Return a const & from NameMap to avoid potential deep copies When I introduced NameMap it was only used with pointers, but now it is also used with std::string so it probably makes sense to keep a default- constructed value around so that a reference can be returned rather than a copy. NameMap::find was renamed to NameMap::value to make it more clear that it doesn't return an iterator, like std::map::find. Reviewed-by: Yohann Ferreira Reviewed-by: Ben Longbons --- src/game-server/itemmanager.cpp | 2 +- src/game-server/map.h | 4 ++-- src/game-server/monstermanager.cpp | 2 +- src/game-server/skillmanager.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/game-server') diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 9d94c389..0a428e51 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -64,7 +64,7 @@ ItemClass *ItemManager::getItem(int itemId) const ItemClass *ItemManager::getItemByName(const std::string &name) const { - return mItemClassesByName.find(name); + return mItemClassesByName.value(name); } unsigned int ItemManager::getDatabaseVersion() const diff --git a/src/game-server/map.h b/src/game-server/map.h index eca36863..28faed7f 100644 --- a/src/game-server/map.h +++ b/src/game-server/map.h @@ -80,8 +80,8 @@ class MapObject mProperties.insert(key, value); } - std::string getProperty(const std::string &key) const - { return mProperties.find(key); } + const std::string &getProperty(const std::string &key) const + { return mProperties.value(key); } const std::string &getName() const { return mName; } diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index b7efd003..0f1686ca 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -350,7 +350,7 @@ void MonsterManager::deinitialize() MonsterClass *MonsterManager::getMonsterByName(const std::string &name) const { - return mMonsterClassesByName.find(name); + return mMonsterClassesByName.value(name); } MonsterClass *MonsterManager::getMonster(int id) const diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp index be6eef4b..0ed327b1 100644 --- a/src/game-server/skillmanager.cpp +++ b/src/game-server/skillmanager.cpp @@ -171,7 +171,7 @@ unsigned int SkillManager::getId(const std::string& set, const std::string &name) const { std::string key = utils::toLower(set) + "_" + utils::toLower(name); - SkillInfo *skillInfo = mNamedSkillsInfo.find(key); + SkillInfo *skillInfo = mNamedSkillsInfo.value(key); return skillInfo ? skillInfo->id : 0; } -- cgit v1.2.3-70-g09d2