optimizations to entry (using std::maps find instead of linear search)
This commit is contained in:
parent
c7c784170f
commit
950c9bd879
|
@ -92,13 +92,10 @@ namespace libtorrent
|
||||||
|
|
||||||
entry& entry::operator[](char const* key)
|
entry& entry::operator[](char const* key)
|
||||||
{
|
{
|
||||||
dictionary_type::iterator i = std::find_if(
|
dictionary_type::iterator i = dict().find(key);
|
||||||
dict().begin()
|
|
||||||
, dict().end()
|
|
||||||
, compare_string(key));
|
|
||||||
if (i != dict().end()) return i->second;
|
if (i != dict().end()) return i->second;
|
||||||
dictionary_type::iterator ret = dict().insert(
|
dictionary_type::iterator ret = dict().insert(
|
||||||
dict().end()
|
dict().begin()
|
||||||
, std::make_pair(std::string(key), entry()));
|
, std::make_pair(std::string(key), entry()));
|
||||||
return ret->second;
|
return ret->second;
|
||||||
}
|
}
|
||||||
|
@ -122,23 +119,16 @@ namespace libtorrent
|
||||||
|
|
||||||
entry const* entry::find_key(char const* key) const
|
entry const* entry::find_key(char const* key) const
|
||||||
{
|
{
|
||||||
dictionary_type::const_iterator i = std::find_if(
|
dictionary_type::const_iterator i = dict().find(key);
|
||||||
dict().begin()
|
|
||||||
, dict().end()
|
|
||||||
, compare_string(key));
|
|
||||||
if (i == dict().end()) return 0;
|
if (i == dict().end()) return 0;
|
||||||
return &i->second;
|
return &i->second;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const entry& entry::operator[](char const* key) const
|
const entry& entry::operator[](char const* key) const
|
||||||
{
|
{
|
||||||
dictionary_type::const_iterator i = std::find_if(
|
dictionary_type::const_iterator i = dict().find(key);
|
||||||
dict().begin()
|
if (i == dict().end()) throw type_error(
|
||||||
, dict().end()
|
(std::string("key not found: ") + key).c_str());
|
||||||
, compare_string(key));
|
|
||||||
if (i == dict().end()) throw type_error("key not found");
|
|
||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,3 +336,4 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue