From 31ccca0778db85c159634478b4ec7997f6704860 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 11 Mar 2020 11:32:04 +0100 Subject: BASELINE: Update Chromium to 80.0.3987.136 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I98e1649aafae85ba3a83e67af00bb27ef301db7b Reviewed-by: Jüri Valdmann --- chromium/base/values.cc | 99 +++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 49 deletions(-) (limited to 'chromium/base/values.cc') 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 #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 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::Insert( + CheckedContiguousConstIterator 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 iter) { - const auto offset = iter - static_cast(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(static_cast(this)->FindKey(key)); + return const_cast(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( - static_cast(this)->FindKeyOfType(key, type)); + return const_cast(as_const(*this).FindKeyOfType(key, type)); } const Value* Value::FindKeyOfType(StringPiece key, Type type) const { @@ -558,7 +578,7 @@ Optional Value::ExtractKey(StringPiece key) { } Value* Value::FindPath(StringPiece path) { - return const_cast(const_cast(this)->FindPath(path)); + return const_cast(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( - const_cast(this)->FindPathOfType(path, type)); + return const_cast(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( - static_cast(this)->FindStringPath(path)); + return const_cast(as_const(*this).FindStringPath(path)); } const Value::BlobStorage* Value::FindBlobPath(StringPiece path) const { @@ -704,11 +722,11 @@ Optional Value::ExtractPath(StringPiece path) { // DEPRECATED METHODS Value* Value::FindPath(std::initializer_list path) { - return const_cast(const_cast(this)->FindPath(path)); + return const_cast(as_const(*this).FindPath(path)); } Value* Value::FindPath(span path) { - return const_cast(const_cast(this)->FindPath(path)); + return const_cast(as_const(*this).FindPath(path)); } const Value* Value::FindPath(std::initializer_list path) const { @@ -727,13 +745,11 @@ const Value* Value::FindPath(span path) const { Value* Value::FindPathOfType(std::initializer_list path, Type type) { - return const_cast( - const_cast(this)->FindPathOfType(path, type)); + return const_cast(as_const(*this).FindPathOfType(path, type)); } Value* Value::FindPathOfType(span path, Type type) { - return const_cast( - const_cast(this)->FindPathOfType(path, type)); + return const_cast(as_const(*this).FindPathOfType(path, type)); } const Value* Value::FindPathOfType(std::initializer_list 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(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(*this).Get( - path, - const_cast(out_value)); + return as_const(*this).Get(path, const_cast(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(*this).GetBinary( - path, const_cast(out_value)); + return as_const(*this).GetBinary(path, const_cast(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(*this).GetDictionary( - path, - const_cast(out_value)); + return as_const(*this).GetDictionary( + path, const_cast(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(*this).GetList( - path, - const_cast(out_value)); + return as_const(*this).GetList(path, + const_cast(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(*this).GetWithoutPathExpansion( - key, - const_cast(out_value)); + return as_const(*this).GetWithoutPathExpansion( + key, const_cast(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(*this); - return const_this.GetDictionaryWithoutPathExpansion( - key, - const_cast(out_value)); + return as_const(*this).GetDictionaryWithoutPathExpansion( + key, const_cast(out_value)); } bool DictionaryValue::GetListWithoutPathExpansion( @@ -1516,10 +1523,8 @@ bool DictionaryValue::GetListWithoutPathExpansion( bool DictionaryValue::GetListWithoutPathExpansion(StringPiece key, ListValue** out_value) { - return - static_cast(*this).GetListWithoutPathExpansion( - key, - const_cast(out_value)); + return as_const(*this).GetListWithoutPathExpansion( + key, const_cast(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(*this).Get( - index, - const_cast(out_value)); + return as_const(*this).Get(index, const_cast(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(*this).GetDictionary( - index, - const_cast(out_value)); + return as_const(*this).GetDictionary( + index, const_cast(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(*this).GetList( - index, - const_cast(out_value)); + return as_const(*this).GetList(index, + const_cast(out_value)); } bool ListValue::Remove(size_t index, std::unique_ptr* out_value) { -- cgit v1.2.3