Remove unnecessary Dictionary::Contains calls

fixes #12457
This commit is contained in:
Gunnar Beutner 2016-08-16 22:03:30 +02:00
parent 520be9513b
commit 162e31b083
2 changed files with 9 additions and 7 deletions

View File

@ -159,11 +159,9 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
const String& key = tokens[i];
prefix += "." + key;
if (!dict->Contains(key)) {
if (!dict->Get(key, &current)) {
current = new Dictionary();
dict->Set(key, current);
} else {
current = dict->Get(key);
}
}

View File

@ -36,14 +36,16 @@ Dictionary::Ptr ScriptGlobal::m_Globals = new Dictionary();
Value ScriptGlobal::Get(const String& name, const Value *defaultValue)
{
if (!m_Globals->Contains(name)) {
Value result;
if (!m_Globals->Get(name, &result)) {
if (defaultValue)
return *defaultValue;
BOOST_THROW_EXCEPTION(std::invalid_argument("Tried to access undefined script variable '" + name + "'"));
}
return m_Globals->Get(name);
return result;
}
void ScriptGlobal::Set(const String& name, const Value& value)
@ -63,12 +65,14 @@ void ScriptGlobal::Set(const String& name, const Value& value)
const String& token = tokens[i];
if (i + 1 != tokens.size()) {
if (!parent->Contains(token)) {
Value vparent;
if (!parent->Get(token, &vparent)) {
Dictionary::Ptr dict = new Dictionary();
parent->Set(token, dict);
parent = dict;
} else {
parent = parent->Get(token);
parent = vparent;
}
}
}