Adapt config::child_or_empty to return a reference instead of a copy.

This might make no difference when the compiler performs copy elision.
In other cases, this should be more efficient, at least when the
child exists, particularly if a large child exists.
This commit is contained in:
JaMiT 2013-11-17 15:47:57 -06:00
parent 4ab33959c1
commit c101fb721b
2 changed files with 5 additions and 4 deletions

View file

@ -618,15 +618,16 @@ const config& config::child(
return tconfig_implementation::child(this, key, parent);
}
config config::child_or_empty(const std::string& key) const
const config & config::child_or_empty(const std::string& key) const
{
static const config empty_cfg;
check_valid();
child_map::const_iterator i = children.find(key);
if (i != children.end() && !i->second.empty())
return *i->second.front();
return config();
return empty_cfg;
}
config &config::child_or_add(const std::string &key)

View file

@ -338,9 +338,9 @@ public:
bool has_child(const std::string& key) const;
/**
* Copies the first child with the given @a key, or an empty config if there is none.
* Returns the first child with the given @a key, or an empty config if there is none.
*/
config child_or_empty(const std::string &key) const;
const config & child_or_empty(const std::string &key) const;
/**
* Returns the nth child with the given @a key, or