summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-17 00:42:38 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-03-17 00:57:16 +0100
commit9344a79233882ac278b3812b91b6edf874ef5d16 (patch)
treee5bd324104a9d8dcf1839de8a880845f8739a37a /src/game-server
parent0e24b15a386d45f43cea76c1b8ad744728a3190e (diff)
downloadmanaserv-9344a79233882ac278b3812b91b6edf874ef5d16.tar.gz
manaserv-9344a79233882ac278b3812b91b6edf874ef5d16.tar.bz2
manaserv-9344a79233882ac278b3812b91b6edf874ef5d16.tar.xz
manaserv-9344a79233882ac278b3812b91b6edf874ef5d16.zip
Micro-optimizations related to std::string
* Rely on the fact that a std::string is empty by default * Use std::string::empty() rather than comparing to "" * Construct with std::string() rather than from "" Reviewed-by: Bertram
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/attributemanager.cpp11
-rw-r--r--src/game-server/commandhandler.cpp46
-rw-r--r--src/game-server/itemmanager.cpp24
-rw-r--r--src/game-server/main-game.cpp2
-rw-r--r--src/game-server/mapcomposite.cpp4
-rw-r--r--src/game-server/mapreader.cpp24
-rw-r--r--src/game-server/monster.h3
-rw-r--r--src/game-server/monstermanager.cpp3
-rw-r--r--src/game-server/statusmanager.cpp2
9 files changed, 66 insertions, 53 deletions
diff --git a/src/game-server/attributemanager.cpp b/src/game-server/attributemanager.cpp
index d590a951..d6cdeae1 100644
--- a/src/game-server/attributemanager.cpp
+++ b/src/game-server/attributemanager.cpp
@@ -79,11 +79,14 @@ void AttributeManager::reload()
if (xmlStrEqual(subnode->name, BAD_CAST "modifier"))
{
std::string sType = utils::toUpper(
- XML::getProperty(subnode, "stacktype", ""));
+ XML::getProperty(subnode, "stacktype",
+ std::string()));
std::string eType = utils::toUpper(
- XML::getProperty(subnode, "modtype", ""));
+ XML::getProperty(subnode, "modtype",
+ std::string()));
std::string tag = utils::toUpper(
- XML::getProperty(subnode, "tag", ""));
+ XML::getProperty(subnode, "tag",
+ std::string()));
AT_TY pSType;
AME_TY pEType;
if (!sType.empty())
@@ -124,7 +127,7 @@ void AttributeManager::reload()
mAttributeMap[id].second.push_back(
AttributeInfoType(pSType, pEType));
std::string tag = XML::getProperty(
- subnode, "tag", "");
+ subnode, "tag", std::string());
if (!tag.empty())
mTagMap.insert(
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp
index 3e385360..d68ffb0e 100644
--- a/src/game-server/commandhandler.cpp
+++ b/src/game-server/commandhandler.cpp
@@ -155,12 +155,12 @@ static bool checkPermission(Character *player, unsigned int permissions)
*/
static std::string getArgument(std::string &args)
{
- std::string argument = "";
+ std::string argument;
std::string::size_type pos = std::string::npos;
bool doubleQuotes = false;
// Finds out if the next argument is between double-quotes
- if (args.substr(0, 1).compare("\""))
+ if (args.empty() || args.at(0) != '"')
{
// No double-quotes, we then search an ending space.
pos = args.find(' ');
@@ -193,7 +193,7 @@ static std::string getArgument(std::string &args)
else
{
argument = args.substr(0);
- args = "";
+ args = std::string();
}
return argument;
}
@@ -218,7 +218,7 @@ static Character* getPlayer(const std::string &player)
static void handleHelp(Character *player, std::string &args)
{
- if (args == "")
+ if (args.empty())
{
// short list of all commands
say("=Available Commands=", player);
@@ -266,7 +266,7 @@ static void handleWarp(Character *player, std::string &args)
std::string ystr = getArgument(args);
// if any of them are empty strings, no argument was given
- if (mapstr == "" || xstr == "" || ystr == "")
+ if (mapstr.empty() || xstr.empty() || ystr.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @warp <map> <x> <y>", player);
@@ -352,7 +352,7 @@ static void handleCharWarp(Character *player, std::string &args)
std::string ystr = getArgument(args);
// if any of them are empty strings, no argument was given
- if (character == "" || mapstr == "" || xstr == "" || ystr == "")
+ if (character.empty() || mapstr.empty() || xstr.empty() || ystr.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @warp <character> <map> <x> <y>", player);
@@ -454,7 +454,7 @@ static void handleItem(Character *player, std::string &args)
std::string valuestr = getArgument(args);
// check all arguments are there
- if (character == "" || itemclass == "")
+ if (character.empty() || itemclass.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @item <character> <item> [amount]", player);
@@ -494,7 +494,7 @@ static void handleItem(Character *player, std::string &args)
}
//identify the amount
- if (valuestr == "")
+ if (valuestr.empty())
{
value = 1;
}
@@ -528,7 +528,7 @@ static void handleDrop(Character *player, std::string &args)
std::string valuestr = getArgument(args);
// check all arguments are there
- if (itemclass == "" )
+ if (itemclass.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @drop <item> [amount]", player);
@@ -552,7 +552,7 @@ static void handleDrop(Character *player, std::string &args)
}
//identify the amount
- if (valuestr == "")
+ if (valuestr.empty())
{
value = 1;
}
@@ -589,7 +589,7 @@ static void handleMoney(Character *player, std::string &args)
std::string valuestr = getArgument(args);
// check all arguments are there
- if (character == "" || valuestr == "")
+ if (character.empty() || valuestr.empty())
{
say("Invalid number of arguments given", player);
say("Usage: @money <character> <amount>", player);
@@ -643,7 +643,7 @@ static void handleSpawn(Character *player, std::string &args)
std::string valuestr = getArgument(args);
// check all arguments are there
- if (monsterclass == "")
+ if (monsterclass.empty())
{
say("Invalid amount of arguments given.", player);
say("Usage: @spawn <monster> [number]", player);
@@ -668,7 +668,7 @@ static void handleSpawn(Character *player, std::string &args)
}
//identify the amount
- if (valuestr == "")
+ if (valuestr.empty())
{
value = 1;
}
@@ -710,7 +710,7 @@ static void handleGoto(Character *player, std::string &args)
std::string character = getArgument(args);
// check all arguments are there
- if (character == "")
+ if (character.empty())
{
say("Invalid amount of arguments given.", player);
say("Usage: @goto <character>", player);
@@ -744,7 +744,7 @@ static void handleRecall(Character *player, std::string &args)
std::string character = getArgument(args);
// check all arguments are there
- if (character == "")
+ if (character.empty())
{
say("Invalid amount of arguments given.", player);
say("Usage: @recall <character>", player);
@@ -782,7 +782,7 @@ static void handleBan(Character *player, std::string &args)
std::string valuestr = getArgument(args);
// check all arguments are there
- if (character == "" || valuestr == "")
+ if (character.empty() || valuestr.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @ban <character> <duration>", player);
@@ -830,7 +830,7 @@ static void handleGivePermission(Character *player, std::string &args)
std::string strPermission = getArgument(args);
// check all arguments are there
- if (character == "" || strPermission == "")
+ if (character.empty() || strPermission.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @givepermission <character> <permission class>", player);
@@ -888,7 +888,7 @@ static void handleTakePermission(Character *player, std::string &args)
std::string strPermission = getArgument(args);
// check all arguments are there
- if (character == "" || strPermission == "")
+ if (character.empty() || strPermission.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @takepermission <character> <permission class>", player);
@@ -948,7 +948,7 @@ static void handleAttribute(Character *player, std::string &args)
std::string valuestr = getArgument(args);
// check all arguments are there
- if (character == "" || valuestr == "" || attrstr == "")
+ if (character.empty() || valuestr.empty() || attrstr.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @attribute <character> <attribute> <value>", player);
@@ -1010,7 +1010,7 @@ static void handleReport(Character *player, std::string &args)
{
std::string bugReport = getArgument(args);
- if (bugReport == "")
+ if (bugReport.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @report <message>", player);
@@ -1022,7 +1022,7 @@ static void handleReport(Character *player, std::string &args)
static void handleAnnounce(Character *player, std::string &msg)
{
- if (msg == "")
+ if (msg.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @announce <message>", player);
@@ -1209,7 +1209,7 @@ static void handleKick(Character *player, std::string &args)
static void handleLog(Character *player, std::string &msg)
{
- if (msg == "")
+ if (msg.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @log <message>", player);
@@ -1226,7 +1226,7 @@ static void handleLog(Character *player, std::string &msg)
static void handleLogsay(Character *player, std::string &msg)
{
- if (msg == "")
+ if (msg.empty())
{
say("Invalid number of arguments given.", player);
say("Usage: @logsay <message>", player);
diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp
index 33bced02..0fe464ee 100644
--- a/src/game-server/itemmanager.cpp
+++ b/src/game-server/itemmanager.cpp
@@ -73,8 +73,9 @@ void ItemManager::reload()
{
if (xmlStrEqual(node->name, BAD_CAST "slot"))
{
- std::string name = XML::getProperty(node, "name", "");
- int count = XML::getProperty(node, "count", 0);
+ const std::string name = XML::getProperty(node, "name",
+ std::string());
+ const int count = XML::getProperty(node, "count", 0);
if (name.empty() || !count || count < 0)
LOG_WARN("Item Manager: equip slot has no name or zero count");
else
@@ -137,7 +138,7 @@ void ItemManager::reload()
// Type is mostly unused, but still serves for
// hairsheets and race sheets.
- std::string sItemType = XML::getProperty(node, "type", "");
+ std::string sItemType = XML::getProperty(node, "type", std::string());
if (sItemType == "hairsprite" || sItemType == "racesprite")
continue;
@@ -178,7 +179,8 @@ void ItemManager::reload()
for_each_xml_child_node(equipnode, subnode)
if (xmlStrEqual(equipnode->name, BAD_CAST "slot"))
{
- std::string slot = XML::getProperty(equipnode, "type", "");
+ std::string slot = XML::getProperty(equipnode, "type",
+ std::string());
if (slot.empty())
{
LOG_WARN("Item Manager: empty equip slot definition!");
@@ -200,8 +202,10 @@ void ItemManager::reload()
{
std::pair< ItemTriggerType, ItemTriggerType> triggerTypes;
{
- std::string triggerName = XML::getProperty(subnode, "trigger", ""),
- dispellTrigger = XML::getProperty(subnode, "dispell", "");
+ const std::string triggerName = XML::getProperty(
+ subnode, "trigger", std::string());
+ const std::string dispellTrigger = XML::getProperty(
+ subnode, "dispell", std::string());
// label -> { trigger (apply), trigger (cancel (default)) }
// The latter can be overridden.
static std::map<const std::string,
@@ -255,7 +259,7 @@ void ItemManager::reload()
{
if (xmlStrEqual(effectnode->name, BAD_CAST "modifier"))
{
- std::string tag = XML::getProperty(effectnode, "attribute", "");
+ std::string tag = XML::getProperty(effectnode, "attribute", std::string());
if (tag.empty())
{
LOG_WARN("Item Manager: Warning, modifier found "
@@ -292,13 +296,13 @@ void ItemManager::reload()
item->addEffect(new ItemEffectConsumes(), triggerTypes.first);
else if (xmlStrEqual(effectnode->name, BAD_CAST "script"))
{
- std::string src = XML::getProperty(effectnode, "src", "");
+ std::string src = XML::getProperty(effectnode, "src", std::string());
if (src.empty())
{
LOG_WARN("Item Manager: Empty src definition for script effect, skipping!");
continue;
}
- std::string func = XML::getProperty(effectnode, "function", "");
+ std::string func = XML::getProperty(effectnode, "function", std::string());
if (func.empty())
{
LOG_WARN ("Item Manager: Empty func definition for script effect, skipping!");
@@ -308,7 +312,7 @@ void ItemManager::reload()
{
// TODO: Load variables from variable subnodes
}
- std::string dfunc = XML::getProperty(effectnode, "dispell-function", "");
+ std::string dfunc = XML::getProperty(effectnode, "dispell-function", std::string());
// STUB
item->addEffect(new ItemEffectScript(), triggerTypes.first, triggerTypes.second);
}
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index c610b7a2..a654d3d2 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -140,7 +140,7 @@ static void initializeConfiguration(std::string configPath = std::string())
LOG_INFO("Using config file: " << configPath);
// Check inter-server password.
- if (Configuration::getValue("net_password", "") == "")
+ if (Configuration::getValue("net_password", std::string()).empty())
{
LOG_FATAL("SECURITY WARNING: 'net_password' not set!");
exit(EXIT_BAD_CONFIG_PARAMETER);
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 56c983f3..d3475f7a 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -551,8 +551,8 @@ void MapComposite::setMap(Map *m)
mContent = new MapContent(m);
std::string sPvP = m->getProperty("pvp");
- if (sPvP == "")
- sPvP = Configuration::getValue("game_defaultPvp", "");
+ if (sPvP.empty())
+ sPvP = Configuration::getValue("game_defaultPvp", std::string());
if (sPvP == "free")
mPvPRules = PVP_FREE;
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index eefca086..80d0a107 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -144,9 +144,11 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
{
if (xmlStrEqual(propNode->name, BAD_CAST "property"))
{
- std::string key = XML::getProperty(propNode, "name", "");
- std::string val = XML::getProperty(propNode, "value", "");
- LOG_DEBUG(" "<<key<<": "<<val);
+ std::string key = XML::getProperty(propNode, "name",
+ std::string());
+ std::string val = XML::getProperty(propNode, "value",
+ std::string());
+ LOG_DEBUG(" " << key << ": " << val);
map->setProperty(key, val);
}
}
@@ -169,8 +171,10 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
continue;
}
- std::string objName = XML::getProperty(objectNode, "name", "");
- std::string objType = XML::getProperty(objectNode, "type", "");
+ std::string objName = XML::getProperty(objectNode, "name",
+ std::string());
+ std::string objType = XML::getProperty(objectNode, "type",
+ std::string());
objType = utils::toUpper(objType);
int objX = XML::getProperty(objectNode, "x", 0);
int objY = XML::getProperty(objectNode, "y", 0);
@@ -217,7 +221,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
}
}
- if (destMapName != "" && destX != -1 && destY != -1)
+ if (!destMapName.empty() && destX != -1 && destY != -1)
{
MapComposite *destMap = MapManager::getMap(destMapName);
if (destMap)
@@ -311,7 +315,7 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
}
else if (utils::compareStrI(value, "SCRIPT") == 0)
{
- scriptText = getObjectProperty(propertyNode, "");
+ scriptText = getObjectProperty(propertyNode, std::string());
}
}
}
@@ -350,11 +354,13 @@ Map* MapReader::readMap(xmlNodePtr node, const std::string &path,
{
if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
{
- std::string value = XML::getProperty(propertyNode, "name", std::string());
+ std::string value = XML::getProperty(propertyNode, "name",
+ std::string());
value = utils::toUpper(value);
if (utils::compareStrI(value, "FILENAME") == 0)
{
- scriptFilename = getObjectProperty(propertyNode, "");
+ scriptFilename = getObjectProperty(propertyNode,
+ std::string());
utils::trim(scriptFilename);
}
else if (utils::compareStrI(value, "TEXT") == 0)
diff --git a/src/game-server/monster.h b/src/game-server/monster.h
index 78a4bddc..a9512146 100644
--- a/src/game-server/monster.h
+++ b/src/game-server/monster.h
@@ -79,8 +79,7 @@ class MonsterClass
mStrollRange(0),
mMutation(0),
mAttackDistance(0),
- mOptimalLevel(0),
- mScript("")
+ mOptimalLevel(0)
{}
/**
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index 0810164f..a719e1a8 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -239,7 +239,8 @@ void MonsterManager::reload()
att->aftDelay = XML::getProperty(subnode, "aft-delay", 0);
att->range = XML::getProperty(subnode, "range", 0);
att->scriptFunction = XML::getProperty(subnode,
- "script-function", "");
+ "script-function",
+ std::string());
std::string sElement = XML::getProperty(subnode,
"element", "neutral");
att->element = elementFromString(sElement);
diff --git a/src/game-server/statusmanager.cpp b/src/game-server/statusmanager.cpp
index 5e9bfcb6..3d79d892 100644
--- a/src/game-server/statusmanager.cpp
+++ b/src/game-server/statusmanager.cpp
@@ -73,7 +73,7 @@ void StatusManager::reload()
continue;
}
- std::string scriptFile = XML::getProperty(node, "script", "");
+ std::string scriptFile = XML::getProperty(node, "script", std::string());
//TODO: Get these modifiers
/*
modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_MIN, XML::getProperty(node, "attack-min", 0));