diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-11 11:32:04 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-18 13:40:17 +0000 |
commit | 31ccca0778db85c159634478b4ec7997f6704860 (patch) | |
tree | 3d33fc3afd9d5ec95541e1bbe074a9cf8da12a0e /chromium/base/values.cc | |
parent | 248b70b82a40964d5594eb04feca0fa36716185d (diff) |
BASELINE: Update Chromium to 80.0.3987.136
Change-Id: I98e1649aafae85ba3a83e67af00bb27ef301db7b
Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'chromium/base/values.cc')
-rw-r--r-- | chromium/base/values.cc | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/chromium/base/values.cc b/chromium/base/values.cc index 6886b846e8d..66e8d39abf0 100644 --- a/chromium/base/values.cc +++ b/chromium/base/values.cc @@ -13,6 +13,7 @@ #include <utility> #include "base/bit_cast.h" +#include "base/containers/checked_iterators.h" #include "base/json/json_writer.h" #include "base/logging.h" #include "base/memory/ptr_util.h" @@ -347,7 +348,7 @@ Value::ListStorage& Value::GetList() { return list_; } -span<const Value> Value::GetList() const { +Value::ConstListView Value::GetList() const { CHECK(is_list()); return list_; } @@ -402,6 +403,21 @@ void Value::Append(Value&& value) { list_.emplace_back(std::move(value)); } +Value::ListStorage::iterator Value::Insert(ListStorage::const_iterator pos, + Value&& value) { + CHECK(is_list()); + return list_.insert(pos, std::move(value)); +} + +CheckedContiguousIterator<Value> Value::Insert( + CheckedContiguousConstIterator<Value> pos, + Value&& value) { + CHECK(is_list()); + const auto offset = pos - make_span(list_).begin(); + list_.insert(list_.begin() + offset, std::move(value)); + return make_span(list_).begin() + offset; +} + bool Value::EraseListIter(ListStorage::const_iterator iter) { CHECK(is_list()); if (iter == list_.end()) @@ -412,7 +428,7 @@ bool Value::EraseListIter(ListStorage::const_iterator iter) { } bool Value::EraseListIter(CheckedContiguousConstIterator<Value> iter) { - const auto offset = iter - static_cast<const Value*>(this)->GetList().begin(); + const auto offset = iter - as_const(*this).GetList().begin(); return EraseListIter(list_.begin() + offset); } @@ -420,8 +436,13 @@ size_t Value::EraseListValue(const Value& val) { return EraseListValueIf([&val](const Value& other) { return val == other; }); } +void Value::ClearList() { + CHECK(is_list()); + list_.clear(); +} + Value* Value::FindKey(StringPiece key) { - return const_cast<Value*>(static_cast<const Value*>(this)->FindKey(key)); + return const_cast<Value*>(as_const(*this).FindKey(key)); } const Value* Value::FindKey(StringPiece key) const { @@ -433,8 +454,7 @@ const Value* Value::FindKey(StringPiece key) const { } Value* Value::FindKeyOfType(StringPiece key, Type type) { - return const_cast<Value*>( - static_cast<const Value*>(this)->FindKeyOfType(key, type)); + return const_cast<Value*>(as_const(*this).FindKeyOfType(key, type)); } const Value* Value::FindKeyOfType(StringPiece key, Type type) const { @@ -558,7 +578,7 @@ Optional<Value> Value::ExtractKey(StringPiece key) { } Value* Value::FindPath(StringPiece path) { - return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path)); + return const_cast<Value*>(as_const(*this).FindPath(path)); } const Value* Value::FindPath(StringPiece path) const { @@ -573,8 +593,7 @@ const Value* Value::FindPath(StringPiece path) const { } Value* Value::FindPathOfType(StringPiece path, Type type) { - return const_cast<Value*>( - const_cast<const Value*>(this)->FindPathOfType(path, type)); + return const_cast<Value*>(as_const(*this).FindPathOfType(path, type)); } const Value* Value::FindPathOfType(StringPiece path, Type type) const { @@ -617,8 +636,7 @@ const std::string* Value::FindStringPath(StringPiece path) const { } std::string* Value::FindStringPath(StringPiece path) { - return const_cast<std::string*>( - static_cast<const Value*>(this)->FindStringPath(path)); + return const_cast<std::string*>(as_const(*this).FindStringPath(path)); } const Value::BlobStorage* Value::FindBlobPath(StringPiece path) const { @@ -704,11 +722,11 @@ Optional<Value> Value::ExtractPath(StringPiece path) { // DEPRECATED METHODS Value* Value::FindPath(std::initializer_list<StringPiece> path) { - return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path)); + return const_cast<Value*>(as_const(*this).FindPath(path)); } Value* Value::FindPath(span<const StringPiece> path) { - return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path)); + return const_cast<Value*>(as_const(*this).FindPath(path)); } const Value* Value::FindPath(std::initializer_list<StringPiece> path) const { @@ -727,13 +745,11 @@ const Value* Value::FindPath(span<const StringPiece> path) const { Value* Value::FindPathOfType(std::initializer_list<StringPiece> path, Type type) { - return const_cast<Value*>( - const_cast<const Value*>(this)->FindPathOfType(path, type)); + return const_cast<Value*>(as_const(*this).FindPathOfType(path, type)); } Value* Value::FindPathOfType(span<const StringPiece> path, Type type) { - return const_cast<Value*>( - const_cast<const Value*>(this)->FindPathOfType(path, type)); + return const_cast<Value*>(as_const(*this).FindPathOfType(path, type)); } const Value* Value::FindPathOfType(std::initializer_list<StringPiece> path, @@ -895,7 +911,7 @@ bool Value::GetAsString(string16* out_value) const { bool Value::GetAsString(const Value** out_value) const { if (out_value && is_string()) { - *out_value = static_cast<const Value*>(this); + *out_value = this; return true; } return is_string(); @@ -1293,9 +1309,7 @@ bool DictionaryValue::Get(StringPiece path, } bool DictionaryValue::Get(StringPiece path, Value** out_value) { - return static_cast<const DictionaryValue&>(*this).Get( - path, - const_cast<const Value**>(out_value)); + return as_const(*this).Get(path, const_cast<const Value**>(out_value)); } bool DictionaryValue::GetBoolean(StringPiece path, bool* bool_value) const { @@ -1368,8 +1382,7 @@ bool DictionaryValue::GetBinary(StringPiece path, } bool DictionaryValue::GetBinary(StringPiece path, Value** out_value) { - return static_cast<const DictionaryValue&>(*this).GetBinary( - path, const_cast<const Value**>(out_value)); + return as_const(*this).GetBinary(path, const_cast<const Value**>(out_value)); } bool DictionaryValue::GetDictionary(StringPiece path, @@ -1387,9 +1400,8 @@ bool DictionaryValue::GetDictionary(StringPiece path, bool DictionaryValue::GetDictionary(StringPiece path, DictionaryValue** out_value) { - return static_cast<const DictionaryValue&>(*this).GetDictionary( - path, - const_cast<const DictionaryValue**>(out_value)); + return as_const(*this).GetDictionary( + path, const_cast<const DictionaryValue**>(out_value)); } bool DictionaryValue::GetList(StringPiece path, @@ -1406,9 +1418,8 @@ bool DictionaryValue::GetList(StringPiece path, } bool DictionaryValue::GetList(StringPiece path, ListValue** out_value) { - return static_cast<const DictionaryValue&>(*this).GetList( - path, - const_cast<const ListValue**>(out_value)); + return as_const(*this).GetList(path, + const_cast<const ListValue**>(out_value)); } bool DictionaryValue::GetWithoutPathExpansion(StringPiece key, @@ -1425,9 +1436,8 @@ bool DictionaryValue::GetWithoutPathExpansion(StringPiece key, bool DictionaryValue::GetWithoutPathExpansion(StringPiece key, Value** out_value) { - return static_cast<const DictionaryValue&>(*this).GetWithoutPathExpansion( - key, - const_cast<const Value**>(out_value)); + return as_const(*this).GetWithoutPathExpansion( + key, const_cast<const Value**>(out_value)); } bool DictionaryValue::GetBooleanWithoutPathExpansion(StringPiece key, @@ -1493,11 +1503,8 @@ bool DictionaryValue::GetDictionaryWithoutPathExpansion( bool DictionaryValue::GetDictionaryWithoutPathExpansion( StringPiece key, DictionaryValue** out_value) { - const DictionaryValue& const_this = - static_cast<const DictionaryValue&>(*this); - return const_this.GetDictionaryWithoutPathExpansion( - key, - const_cast<const DictionaryValue**>(out_value)); + return as_const(*this).GetDictionaryWithoutPathExpansion( + key, const_cast<const DictionaryValue**>(out_value)); } bool DictionaryValue::GetListWithoutPathExpansion( @@ -1516,10 +1523,8 @@ bool DictionaryValue::GetListWithoutPathExpansion( bool DictionaryValue::GetListWithoutPathExpansion(StringPiece key, ListValue** out_value) { - return - static_cast<const DictionaryValue&>(*this).GetListWithoutPathExpansion( - key, - const_cast<const ListValue**>(out_value)); + return as_const(*this).GetListWithoutPathExpansion( + key, const_cast<const ListValue**>(out_value)); } bool DictionaryValue::Remove(StringPiece path, @@ -1649,9 +1654,7 @@ bool ListValue::Get(size_t index, const Value** out_value) const { } bool ListValue::Get(size_t index, Value** out_value) { - return static_cast<const ListValue&>(*this).Get( - index, - const_cast<const Value**>(out_value)); + return as_const(*this).Get(index, const_cast<const Value**>(out_value)); } bool ListValue::GetBoolean(size_t index, bool* bool_value) const { @@ -1708,9 +1711,8 @@ bool ListValue::GetDictionary(size_t index, } bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) { - return static_cast<const ListValue&>(*this).GetDictionary( - index, - const_cast<const DictionaryValue**>(out_value)); + return as_const(*this).GetDictionary( + index, const_cast<const DictionaryValue**>(out_value)); } bool ListValue::GetList(size_t index, const ListValue** out_value) const { @@ -1726,9 +1728,8 @@ bool ListValue::GetList(size_t index, const ListValue** out_value) const { } bool ListValue::GetList(size_t index, ListValue** out_value) { - return static_cast<const ListValue&>(*this).GetList( - index, - const_cast<const ListValue**>(out_value)); + return as_const(*this).GetList(index, + const_cast<const ListValue**>(out_value)); } bool ListValue::Remove(size_t index, std::unique_ptr<Value>* out_value) { |