summaryrefslogtreecommitdiffstats
path: root/chromium/base/values.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 13:57:45 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-19 13:44:40 +0000
commit6ec7b8da05d21a3878bd21c691b41e675d74bb1c (patch)
treeb87f250bc19413750b9bb9cdbf2da20ef5014820 /chromium/base/values.cc
parentec02ee4181c49b61fce1c8fb99292dbb8139cc90 (diff)
BASELINE: Update Chromium to 60.0.3112.70
Change-Id: I9911c2280a014d4632f254857876a395d4baed2d Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/base/values.cc')
-rw-r--r--chromium/base/values.cc230
1 files changed, 111 insertions, 119 deletions
diff --git a/chromium/base/values.cc b/chromium/base/values.cc
index 0dc62b3d399..2f293c9e817 100644
--- a/chromium/base/values.cc
+++ b/chromium/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));
}
}
@@ -75,7 +75,7 @@ std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node) {
// static
std::unique_ptr<Value> Value::CreateWithCopiedBuffer(const char* buffer,
size_t size) {
- return MakeUnique<Value>(std::vector<char>(buffer, buffer + size));
+ return MakeUnique<Value>(BlobStorage(buffer, buffer + size));
}
Value::Value(const Value& that) {
@@ -110,7 +110,7 @@ Value::Value(Type type) : type_(type) {
binary_value_.Init();
return;
case Type::DICTIONARY:
- dict_ptr_.Init(MakeUnique<DictStorage>());
+ dict_.Init();
return;
case Type::LIST:
list_.Init();
@@ -155,16 +155,16 @@ Value::Value(const string16& in_string) : type_(Type::STRING) {
Value::Value(StringPiece in_string) : Value(in_string.as_string()) {}
-Value::Value(const std::vector<char>& in_blob) : type_(Type::BINARY) {
+Value::Value(const BlobStorage& in_blob) : type_(Type::BINARY) {
binary_value_.Init(in_blob);
}
-Value::Value(std::vector<char>&& in_blob) noexcept : type_(Type::BINARY) {
+Value::Value(BlobStorage&& in_blob) noexcept : type_(Type::BINARY) {
binary_value_.Init(std::move(in_blob));
}
Value::Value(DictStorage&& in_dict) noexcept : type_(Type::DICTIONARY) {
- dict_ptr_.Init(MakeUnique<DictStorage>(std::move(in_dict)));
+ dict_.Init(std::move(in_dict));
}
Value::Value(const ListStorage& in_list) : type_(Type::LIST) {
@@ -229,7 +229,7 @@ const std::string& Value::GetString() const {
return *string_value_;
}
-const std::vector<char>& Value::GetBlob() const {
+const Value::BlobStorage& Value::GetBlob() const {
CHECK(is_blob());
return *binary_value_;
}
@@ -244,14 +244,6 @@ const Value::ListStorage& Value::GetList() const {
return *list_;
}
-size_t Value::GetSize() const {
- return GetBlob().size();
-}
-
-const char* Value::GetBuffer() const {
- return GetBlob().data();
-}
-
bool Value::GetAsBoolean(bool* out_value) const {
if (out_value && is_bool()) {
*out_value = bool_value_;
@@ -312,14 +304,6 @@ bool Value::GetAsString(StringPiece* out_value) const {
return is_string();
}
-bool Value::GetAsBinary(const Value** out_value) const {
- if (out_value && is_blob()) {
- *out_value = this;
- return true;
- }
- return is_blob();
-}
-
bool Value::GetAsList(ListValue** out_value) {
if (out_value && is_list()) {
*out_value = static_cast<ListValue*>(this);
@@ -380,10 +364,10 @@ bool operator==(const Value& lhs, const Value& rhs) {
// TODO(crbug.com/646113): Clean this up when DictionaryValue and ListValue
// are completely inlined.
case Value::Type::DICTIONARY:
- if ((*lhs.dict_ptr_)->size() != (*rhs.dict_ptr_)->size())
+ if (lhs.dict_->size() != rhs.dict_->size())
return false;
- return std::equal(std::begin(**lhs.dict_ptr_), std::end(**lhs.dict_ptr_),
- std::begin(**rhs.dict_ptr_),
+ return std::equal(std::begin(*lhs.dict_), std::end(*lhs.dict_),
+ std::begin(*rhs.dict_),
[](const Value::DictStorage::value_type& u,
const Value::DictStorage::value_type& v) {
return std::tie(u.first, *u.second) ==
@@ -422,8 +406,8 @@ bool operator<(const Value& lhs, const Value& rhs) {
// are completely inlined.
case Value::Type::DICTIONARY:
return std::lexicographical_compare(
- std::begin(**lhs.dict_ptr_), std::end(**lhs.dict_ptr_),
- std::begin(**rhs.dict_ptr_), std::end(**rhs.dict_ptr_),
+ std::begin(*lhs.dict_), std::end(*lhs.dict_), std::begin(*rhs.dict_),
+ std::end(*rhs.dict_),
[](const Value::DictStorage::value_type& u,
const Value::DictStorage::value_type& v) {
return std::tie(u.first, *u.second) < std::tie(v.first, *v.second);
@@ -505,11 +489,10 @@ void Value::InternalCopyConstructFrom(const Value& that) {
// TODO(crbug.com/646113): Clean this up when DictStorage can be copied
// directly.
case Type::DICTIONARY:
- dict_ptr_.Init(MakeUnique<DictStorage>());
- for (const auto& it : **that.dict_ptr_) {
- (*dict_ptr_)
- ->emplace_hint((*dict_ptr_)->end(), it.first,
- MakeUnique<Value>(*it.second));
+ dict_.Init();
+ for (const auto& it : *that.dict_) {
+ dict_->emplace_hint(dict_->end(), it.first,
+ MakeUnique<Value>(*it.second));
}
return;
case Type::LIST:
@@ -536,7 +519,7 @@ void Value::InternalMoveConstructFrom(Value&& that) {
binary_value_.InitFromMove(std::move(that.binary_value_));
return;
case Type::DICTIONARY:
- dict_ptr_.InitFromMove(std::move(that.dict_ptr_));
+ dict_.InitFromMove(std::move(that.dict_));
return;
case Type::LIST:
list_.InitFromMove(std::move(that.list_));
@@ -569,7 +552,7 @@ void Value::InternalCopyAssignFromSameType(const Value& that) {
// directly.
case Type::DICTIONARY: {
Value copy = that;
- *dict_ptr_ = std::move(*copy.dict_ptr_);
+ *dict_ = std::move(*copy.dict_);
return;
}
case Type::LIST:
@@ -594,7 +577,7 @@ void Value::InternalCleanup() {
binary_value_.Destroy();
return;
case Type::DICTIONARY:
- dict_ptr_.Destroy();
+ dict_.Destroy();
return;
case Type::LIST:
list_.Destroy();
@@ -619,16 +602,16 @@ DictionaryValue::DictionaryValue() : Value(Type::DICTIONARY) {}
bool DictionaryValue::HasKey(StringPiece key) const {
DCHECK(IsStringUTF8(key));
- auto current_entry = (*dict_ptr_)->find(key.as_string());
- DCHECK((current_entry == (*dict_ptr_)->end()) || current_entry->second);
- return current_entry != (*dict_ptr_)->end();
+ auto current_entry = dict_->find(key.as_string());
+ DCHECK((current_entry == dict_->end()) || current_entry->second);
+ return current_entry != dict_->end();
}
void DictionaryValue::Clear() {
- (*dict_ptr_)->clear();
+ dict_->clear();
}
-void DictionaryValue::Set(StringPiece path, std::unique_ptr<Value> in_value) {
+Value* DictionaryValue::Set(StringPiece path, std::unique_ptr<Value> in_value) {
DCHECK(IsStringUTF8(path));
DCHECK(in_value);
@@ -641,76 +624,97 @@ void 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;
- current_dictionary->SetWithoutPathExpansion(
- key, base::WrapUnique(child_dictionary));
+ child_dictionary = current_dictionary->SetDictionaryWithoutPathExpansion(
+ key, MakeUnique<DictionaryValue>());
}
current_dictionary = child_dictionary;
current_path = current_path.substr(delimiter_position + 1);
}
- current_dictionary->SetWithoutPathExpansion(current_path,
- std::move(in_value));
+ return current_dictionary->SetWithoutPathExpansion(current_path,
+ std::move(in_value));
+}
+
+Value* DictionaryValue::Set(StringPiece path, Value* in_value) {
+ return Set(path, WrapUnique(in_value));
+}
+
+Value* DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
+ return Set(path, MakeUnique<Value>(in_value));
+}
+
+Value* DictionaryValue::SetInteger(StringPiece path, int in_value) {
+ return Set(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::Set(StringPiece path, Value* in_value) {
- Set(path, WrapUnique(in_value));
+Value* DictionaryValue::SetDouble(StringPiece path, double in_value) {
+ return Set(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
- Set(path, new Value(in_value));
+Value* DictionaryValue::SetString(StringPiece path, StringPiece in_value) {
+ return Set(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetInteger(StringPiece path, int in_value) {
- Set(path, new Value(in_value));
+Value* DictionaryValue::SetString(StringPiece path, const string16& in_value) {
+ return Set(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetDouble(StringPiece path, double in_value) {
- Set(path, new Value(in_value));
+DictionaryValue* DictionaryValue::SetDictionary(
+ StringPiece path,
+ std::unique_ptr<DictionaryValue> in_value) {
+ return static_cast<DictionaryValue*>(Set(path, std::move(in_value)));
}
-void DictionaryValue::SetString(StringPiece path, StringPiece in_value) {
- Set(path, new Value(in_value));
+ListValue* DictionaryValue::SetList(StringPiece path,
+ std::unique_ptr<ListValue> in_value) {
+ return static_cast<ListValue*>(Set(path, std::move(in_value)));
}
-void DictionaryValue::SetString(StringPiece path, const string16& in_value) {
- Set(path, new Value(in_value));
+Value* DictionaryValue::SetWithoutPathExpansion(
+ StringPiece key,
+ std::unique_ptr<Value> in_value) {
+ return ((*dict_)[key.as_string()] = std::move(in_value)).get();
}
-void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
- std::unique_ptr<Value> in_value) {
- (**dict_ptr_)[key.as_string()] = std::move(in_value);
+Value* DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path,
+ bool in_value) {
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
- Value* in_value) {
- SetWithoutPathExpansion(key, WrapUnique(in_value));
+Value* DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path,
+ int in_value) {
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetBooleanWithoutPathExpansion(StringPiece path,
- bool in_value) {
- SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+Value* DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path,
+ double in_value) {
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetIntegerWithoutPathExpansion(StringPiece path,
- int in_value) {
- SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+Value* DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
+ StringPiece in_value) {
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetDoubleWithoutPathExpansion(StringPiece path,
- double in_value) {
- SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+Value* DictionaryValue::SetStringWithoutPathExpansion(
+ StringPiece path,
+ const string16& in_value) {
+ return SetWithoutPathExpansion(path, MakeUnique<Value>(in_value));
}
-void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
- StringPiece in_value) {
- SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+DictionaryValue* DictionaryValue::SetDictionaryWithoutPathExpansion(
+ StringPiece path,
+ std::unique_ptr<DictionaryValue> in_value) {
+ return static_cast<DictionaryValue*>(
+ SetWithoutPathExpansion(path, std::move(in_value)));
}
-void DictionaryValue::SetStringWithoutPathExpansion(StringPiece path,
- const string16& in_value) {
- SetWithoutPathExpansion(path, base::MakeUnique<base::Value>(in_value));
+ListValue* DictionaryValue::SetListWithoutPathExpansion(
+ StringPiece path,
+ std::unique_ptr<ListValue> in_value) {
+ return static_cast<ListValue*>(
+ SetWithoutPathExpansion(path, std::move(in_value)));
}
bool DictionaryValue::Get(StringPiece path,
@@ -856,8 +860,8 @@ bool DictionaryValue::GetList(StringPiece path, ListValue** out_value) {
bool DictionaryValue::GetWithoutPathExpansion(StringPiece key,
const Value** out_value) const {
DCHECK(IsStringUTF8(key));
- auto entry_iterator = (*dict_ptr_)->find(key.as_string());
- if (entry_iterator == (*dict_ptr_)->end())
+ auto entry_iterator = dict_->find(key.as_string());
+ if (entry_iterator == dict_->end())
return false;
if (out_value)
@@ -985,13 +989,13 @@ bool DictionaryValue::RemoveWithoutPathExpansion(
StringPiece key,
std::unique_ptr<Value>* out_value) {
DCHECK(IsStringUTF8(key));
- auto entry_iterator = (*dict_ptr_)->find(key.as_string());
- if (entry_iterator == (*dict_ptr_)->end())
+ auto entry_iterator = dict_->find(key.as_string());
+ if (entry_iterator == dict_->end())
return false;
if (out_value)
*out_value = std::move(entry_iterator->second);
- (*dict_ptr_)->erase(entry_iterator);
+ dict_->erase(entry_iterator);
return true;
}
@@ -1020,7 +1024,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;
}
@@ -1044,11 +1048,11 @@ void DictionaryValue::MergeDictionary(const DictionaryValue* dictionary) {
void DictionaryValue::Swap(DictionaryValue* other) {
CHECK(other->is_dict());
- dict_ptr_->swap(*(other->dict_ptr_));
+ dict_->swap(*other->dict_);
}
DictionaryValue::Iterator::Iterator(const DictionaryValue& target)
- : target_(target), it_((*target.dict_ptr_)->begin()) {}
+ : target_(target), it_(target.dict_->begin()) {}
DictionaryValue::Iterator::Iterator(const Iterator& other) = default;
@@ -1076,6 +1080,11 @@ std::unique_ptr<ListValue> ListValue::From(std::unique_ptr<Value> value) {
ListValue::ListValue() : Value(Type::LIST) {}
+ListValue::ListValue(const ListStorage& in_list) : Value(in_list) {}
+
+ListValue::ListValue(ListStorage&& in_list) noexcept
+ : Value(std::move(in_list)) {}
+
void ListValue::Clear() {
list_->clear();
}
@@ -1084,22 +1093,14 @@ void ListValue::Reserve(size_t n) {
list_->reserve(n);
}
-bool ListValue::Set(size_t index, Value* in_value) {
- return Set(index, WrapUnique(in_value));
-}
-
bool ListValue::Set(size_t index, std::unique_ptr<Value> in_value) {
if (!in_value)
return false;
- if (index >= list_->size()) {
- // Pad out any intermediate indexes with null settings
- while (index > list_->size())
- Append(MakeUnique<Value>());
- Append(std::move(in_value));
- } else {
- (*list_)[index] = std::move(*in_value);
- }
+ if (index >= list_->size())
+ list_->resize(index + 1);
+
+ (*list_)[index] = std::move(*in_value);
return true;
}
@@ -1249,45 +1250,36 @@ void ListValue::Append(std::unique_ptr<Value> in_value) {
list_->push_back(std::move(*in_value));
}
-#if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
-void ListValue::Append(Value* in_value) {
- DCHECK(in_value);
- Append(WrapUnique(in_value));
-}
-#endif
-
void ListValue::AppendBoolean(bool in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendInteger(int in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendDouble(double in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendString(StringPiece in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendString(const string16& in_value) {
- Append(MakeUnique<Value>(in_value));
+ list_->emplace_back(in_value);
}
void ListValue::AppendStrings(const std::vector<std::string>& in_values) {
- for (std::vector<std::string>::const_iterator it = in_values.begin();
- it != in_values.end(); ++it) {
- AppendString(*it);
- }
+ list_->reserve(list_->size() + in_values.size());
+ for (const auto& in_value : in_values)
+ list_->emplace_back(in_value);
}
void ListValue::AppendStrings(const std::vector<string16>& in_values) {
- for (std::vector<string16>::const_iterator it = in_values.begin();
- it != in_values.end(); ++it) {
- AppendString(*it);
- }
+ list_->reserve(list_->size() + in_values.size());
+ for (const auto& in_value : in_values)
+ list_->emplace_back(in_value);
}
bool ListValue::AppendIfNotPresent(std::unique_ptr<Value> in_value) {