diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 22:58:52 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 22:58:52 +0000 |
commit | 18a3df6a2dc2db779fcb69ed5f8a12dd418da090 (patch) | |
tree | 9bcd829fb30f10d3e22de945d48eaca3b6358c71 /base | |
parent | b452a7be13836e7f111ab9e6f12c81ba8ef02f69 (diff) | |
download | chromium_src-18a3df6a2dc2db779fcb69ed5f8a12dd418da090.zip chromium_src-18a3df6a2dc2db779fcb69ed5f8a12dd418da090.tar.gz chromium_src-18a3df6a2dc2db779fcb69ed5f8a12dd418da090.tar.bz2 |
Make DictionaryValue::SetWithoutPathExpansion more efficient.
SetWithoutPathExpansion is now always O(log N) rather than O(2 log N) for new insertions and O(3 log N) for replacements. A simple test shows the expected 66% speedup in replacements.
BUG=none
TEST=base_unittests continues to pass
R=jar@chromium.org
Review URL: http://codereview.chromium.org/8374001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106801 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/values.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/base/values.cc b/base/values.cc index 60b0d70..4719741 100644 --- a/base/values.cc +++ b/base/values.cc @@ -412,12 +412,13 @@ void DictionaryValue::SetWithoutPathExpansion(const std::string& key, Value* in_value) { // If there's an existing value here, we need to delete it, because // we own all our children. - if (HasKey(key)) { - DCHECK(dictionary_[key] != in_value); // This would be bogus - delete dictionary_[key]; + std::pair<ValueMap::iterator, bool> ins_res = + dictionary_.insert(std::make_pair(key, in_value)); + if (!ins_res.second) { + DCHECK_NE(ins_res.first->second, in_value); // This would be bogus + delete ins_res.first->second; + ins_res.first->second = in_value; } - - dictionary_[key] = in_value; } bool DictionaryValue::Get(const std::string& path, Value** out_value) const { |