Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: base/json/json_parser.cc

Issue 21030009: Make element removal methods in DictionaryValue and ListValue take scoped_ptr's as outparams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/json/json_reader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/json/json_parser.h" 5 #include "base/json/json_parser.h"
6 6
7 #include "base/float_util.h" 7 #include "base/float_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // new contents, originally from |other|. 49 // new contents, originally from |other|.
50 Clear(); 50 Clear();
51 json_.reset(); 51 json_.reset();
52 DictionaryValue::Swap(copy.get()); 52 DictionaryValue::Swap(copy.get());
53 } 53 }
54 54
55 // Not overriding DictionaryValue::Remove because it just calls through to 55 // Not overriding DictionaryValue::Remove because it just calls through to
56 // the method below. 56 // the method below.
57 57
58 virtual bool RemoveWithoutPathExpansion(const std::string& key, 58 virtual bool RemoveWithoutPathExpansion(const std::string& key,
59 Value** out) OVERRIDE { 59 scoped_ptr<Value>* out) OVERRIDE {
60 // If the caller won't take ownership of the removed value, just call up. 60 // If the caller won't take ownership of the removed value, just call up.
61 if (!out) 61 if (!out)
62 return DictionaryValue::RemoveWithoutPathExpansion(key, out); 62 return DictionaryValue::RemoveWithoutPathExpansion(key, out);
63 63
64 DVLOG(1) << "Remove()ing from a DictionaryValue inefficiently."; 64 DVLOG(1) << "Remove()ing from a DictionaryValue inefficiently.";
65 65
66 // Otherwise, remove the value while its still "owned" by this and copy it 66 // Otherwise, remove the value while its still "owned" by this and copy it
67 // to convert any JSONStringValues to std::string. 67 // to convert any JSONStringValues to std::string.
68 Value* out_owned = NULL; 68 scoped_ptr<Value> out_owned;
69 if (!DictionaryValue::RemoveWithoutPathExpansion(key, &out_owned)) 69 if (!DictionaryValue::RemoveWithoutPathExpansion(key, &out_owned))
70 return false; 70 return false;
71 71
72 *out = out_owned->DeepCopy(); 72 out->reset(out_owned->DeepCopy());
73 delete out_owned;
74 73
75 return true; 74 return true;
76 } 75 }
77 76
78 private: 77 private:
79 scoped_ptr<std::string> json_; 78 scoped_ptr<std::string> json_;
80 79
81 DISALLOW_COPY_AND_ASSIGN(DictionaryHiddenRootValue); 80 DISALLOW_COPY_AND_ASSIGN(DictionaryHiddenRootValue);
82 }; 81 };
83 82
(...skipping 12 matching lines...) Expand all
96 scoped_ptr<base::ListValue> copy(DeepCopy()); 95 scoped_ptr<base::ListValue> copy(DeepCopy());
97 copy->Swap(other); 96 copy->Swap(other);
98 97
99 // Then erase the contents of the current list and swap in the new contents, 98 // Then erase the contents of the current list and swap in the new contents,
100 // originally from |other|. 99 // originally from |other|.
101 Clear(); 100 Clear();
102 json_.reset(); 101 json_.reset();
103 ListValue::Swap(copy.get()); 102 ListValue::Swap(copy.get());
104 } 103 }
105 104
106 virtual bool Remove(size_t index, Value** out) OVERRIDE { 105 virtual bool Remove(size_t index, scoped_ptr<Value>* out) OVERRIDE {
107 // If the caller won't take ownership of the removed value, just call up. 106 // If the caller won't take ownership of the removed value, just call up.
108 if (!out) 107 if (!out)
109 return ListValue::Remove(index, out); 108 return ListValue::Remove(index, out);
110 109
111 DVLOG(1) << "Remove()ing from a ListValue inefficiently."; 110 DVLOG(1) << "Remove()ing from a ListValue inefficiently.";
112 111
113 // Otherwise, remove the value while its still "owned" by this and copy it 112 // Otherwise, remove the value while its still "owned" by this and copy it
114 // to convert any JSONStringValues to std::string. 113 // to convert any JSONStringValues to std::string.
115 Value* out_owned = NULL; 114 scoped_ptr<Value> out_owned;
116 if (!ListValue::Remove(index, &out_owned)) 115 if (!ListValue::Remove(index, &out_owned))
117 return false; 116 return false;
118 117
119 *out = out_owned->DeepCopy(); 118 out->reset(out_owned->DeepCopy());
120 delete out_owned;
121 119
122 return true; 120 return true;
123 } 121 }
124 122
125 private: 123 private:
126 scoped_ptr<std::string> json_; 124 scoped_ptr<std::string> json_;
127 125
128 DISALLOW_COPY_AND_ASSIGN(ListHiddenRootValue); 126 DISALLOW_COPY_AND_ASSIGN(ListHiddenRootValue);
129 }; 127 };
130 128
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 const std::string& description) { 956 const std::string& description) {
959 if (line || column) { 957 if (line || column) {
960 return StringPrintf("Line: %i, column: %i, %s", 958 return StringPrintf("Line: %i, column: %i, %s",
961 line, column, description.c_str()); 959 line, column, description.c_str());
962 } 960 }
963 return description; 961 return description;
964 } 962 }
965 963
966 } // namespace internal 964 } // namespace internal
967 } // namespace base 965 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/trace_event_unittest.cc ('k') | base/json/json_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698