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

Unified Diff: base/values.cc

Issue 2865963002: Use MakeUnique() in base/values.cc. (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index 768e3f790b4c8b1870f070118e5782640e6ce12a..f5e689f31fd0d0004ee4b00de70eabe76c49b507 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -49,7 +49,7 @@ std::unique_ptr<DictionaryValue> CopyDictionaryWithoutEmptyChildren(
std::unique_ptr<Value> child_copy = CopyWithoutEmptyChildren(it.value());
if (child_copy) {
if (!copy)
- copy.reset(new DictionaryValue);
+ copy = MakeUnique<DictionaryValue>();
copy->SetWithoutPathExpansion(it.key(), std::move(child_copy));
}
}
@@ -337,7 +337,7 @@ bool Value::GetAsDictionary(const DictionaryValue** out_value) const {
}
Value* Value::DeepCopy() const {
- return new Value(*this);
+ return CreateDeepCopy().release();
jdoerrie 2017/05/08 22:44:47 I'd rather like for this to stay the same. As the
Lei Zhang 2017/05/08 22:58:30 Done.
}
std::unique_ptr<Value> Value::CreateDeepCopy() const {
@@ -624,9 +624,10 @@ Value* DictionaryValue::Set(StringPiece path, std::unique_ptr<Value> in_value) {
StringPiece key = current_path.substr(0, delimiter_position);
DictionaryValue* child_dictionary = nullptr;
if (!current_dictionary->GetDictionary(key, &child_dictionary)) {
- child_dictionary = new DictionaryValue;
+ auto new_child_dictionary = MakeUnique<DictionaryValue>();
+ child_dictionary = new_child_dictionary.get();
current_dictionary->SetWithoutPathExpansion(
- key, base::WrapUnique(child_dictionary));
+ key, std::move(new_child_dictionary));
jdoerrie 2017/05/08 22:44:47 Consider using the recently added SetDictionaryWit
Lei Zhang 2017/05/08 22:58:30 Done. Thanks.
}
current_dictionary = child_dictionary;
@@ -642,23 +643,23 @@ Value* DictionaryValue::Set(StringPiece path, Value* in_value) {
}
Value* DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
- return Set(path, new Value(in_value));
+ return Set(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetInteger(StringPiece path, int in_value) {
- return Set(path, new Value(in_value));
+ return Set(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetDouble(StringPiece path, double in_value) {
- return Set(path, new Value(in_value));
+ return Set(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetString(StringPiece path, StringPiece in_value) {
- return Set(path, new Value(in_value));
+ return Set(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetString(StringPiece path, const string16& in_value) {
- return Set(path, new Value(in_value));
+ return Set(path, MakeUnique<Value>(in_value));
}
DictionaryValue* DictionaryValue::SetDictionary(
@@ -685,28 +686,28 @@ Value* DictionaryValue::SetWithoutPathExpansion(StringPiece key,
Value* DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path,
bool in_value) {
- return SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path,
int in_value) {
- return SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path,
double in_value) {
- return SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
StringPiece in_value) {
- return SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
Value* DictionaryValue::SetStringWithoutPathExpansion(
StringPiece path,
const string16& in_value) {
- return SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
DictionaryValue* DictionaryValue::SetDictionaryWithoutPathExpansion(
@@ -1030,7 +1031,7 @@ std::unique_ptr<DictionaryValue> DictionaryValue::DeepCopyWithoutEmptyChildren()
std::unique_ptr<DictionaryValue> copy =
CopyDictionaryWithoutEmptyChildren(*this);
if (!copy)
- copy.reset(new DictionaryValue);
+ copy = MakeUnique<DictionaryValue>();
return copy;
}
@@ -1065,7 +1066,7 @@ DictionaryValue::Iterator::Iterator(const Iterator& other) = default;
DictionaryValue::Iterator::~Iterator() {}
DictionaryValue* DictionaryValue::DeepCopy() const {
- return new DictionaryValue(*this);
+ return CreateDeepCopy().release();
jdoerrie 2017/05/08 22:44:47 Same here.
Lei Zhang 2017/05/08 22:58:30 Done.
}
std::unique_ptr<DictionaryValue> DictionaryValue::CreateDeepCopy() const {
@@ -1316,7 +1317,7 @@ void ListValue::Swap(ListValue* other) {
}
ListValue* ListValue::DeepCopy() const {
- return new ListValue(*this);
+ return CreateDeepCopy().release();
jdoerrie 2017/05/08 22:44:48 And here.
Lei Zhang 2017/05/08 22:58:30 Done.
}
std::unique_ptr<ListValue> ListValue::CreateDeepCopy() const {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698