OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/values.h" | 5 #include "base/values.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <ostream> | 10 #include <ostream> |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 | 414 |
415 void DictionaryValue::SetString(const std::string& path, | 415 void DictionaryValue::SetString(const std::string& path, |
416 const string16& in_value) { | 416 const string16& in_value) { |
417 Set(path, new StringValue(in_value)); | 417 Set(path, new StringValue(in_value)); |
418 } | 418 } |
419 | 419 |
420 void DictionaryValue::SetWithoutPathExpansion(const std::string& key, | 420 void DictionaryValue::SetWithoutPathExpansion(const std::string& key, |
421 Value* in_value) { | 421 Value* in_value) { |
422 // If there's an existing value here, we need to delete it, because | 422 // If there's an existing value here, we need to delete it, because |
423 // we own all our children. | 423 // we own all our children. |
424 std::pair<ValueMap::iterator, bool> ins_res = | 424 ValueMap::iterator it = dictionary_.find(key); |
425 dictionary_.insert(std::make_pair(key, in_value)); | 425 if (it == dictionary_.end()) { |
Nico
2014/12/01 16:57:02
Isn't the lhs better here? It requires on-stack al
Georges Khalil
2014/12/01 20:34:11
I'm removing this code from the CL, because it doe
| |
426 if (!ins_res.second) { | 426 dictionary_.insert(std::make_pair(key, in_value)); |
427 DCHECK_NE(ins_res.first->second, in_value); // This would be bogus | 427 } else { |
428 delete ins_res.first->second; | 428 DCHECK_NE(it->second, in_value); // This would be bogus |
429 ins_res.first->second = in_value; | 429 delete it->second; |
430 it->second = in_value; | |
430 } | 431 } |
431 } | 432 } |
432 | 433 |
433 void DictionaryValue::SetBooleanWithoutPathExpansion( | 434 void DictionaryValue::SetBooleanWithoutPathExpansion( |
434 const std::string& path, bool in_value) { | 435 const std::string& path, bool in_value) { |
435 SetWithoutPathExpansion(path, new FundamentalValue(in_value)); | 436 SetWithoutPathExpansion(path, new FundamentalValue(in_value)); |
436 } | 437 } |
437 | 438 |
438 void DictionaryValue::SetIntegerWithoutPathExpansion( | 439 void DictionaryValue::SetIntegerWithoutPathExpansion( |
439 const std::string& path, int in_value) { | 440 const std::string& path, int in_value) { |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 | 1126 |
1126 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1127 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1127 std::string json; | 1128 std::string json; |
1128 JSONWriter::WriteWithOptions(&value, | 1129 JSONWriter::WriteWithOptions(&value, |
1129 JSONWriter::OPTIONS_PRETTY_PRINT, | 1130 JSONWriter::OPTIONS_PRETTY_PRINT, |
1130 &json); | 1131 &json); |
1131 return out << json; | 1132 return out << json; |
1132 } | 1133 } |
1133 | 1134 |
1134 } // namespace base | 1135 } // namespace base |
OLD | NEW |