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

Unified Diff: base/values.cc

Issue 2771923005: Implement comparison operators for base::Value (Closed)
Patch Set: Fix compilation error Created 3 years, 9 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
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index fef999c43b537619d9e5ccc0c1ec966e5e52ae79..e920a7aa7a1a9a7b5e0b740fbc12635303310dcc 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -393,60 +393,17 @@ std::unique_ptr<Value> Value::CreateDeepCopy() const {
}
bool Value::Equals(const Value* other) const {
- if (other->type() != type())
- return false;
-
- switch (type()) {
- case Type::NONE:
- return true;
- case Type::BOOLEAN:
- return bool_value_ == other->bool_value_;
- case Type::INTEGER:
- return int_value_ == other->int_value_;
- case Type::DOUBLE:
- return double_value_ == other->double_value_;
- case Type::STRING:
- return *string_value_ == *(other->string_value_);
- case Type::BINARY:
- return *binary_value_ == *(other->binary_value_);
- // TODO(crbug.com/646113): Clean this up when DictionaryValue and ListValue
- // are completely inlined.
- case Type::DICTIONARY: {
- if ((*dict_ptr_)->size() != (*other->dict_ptr_)->size())
- return false;
-
- return std::equal(std::begin(**dict_ptr_), std::end(**dict_ptr_),
- std::begin(**(other->dict_ptr_)),
- [](const DictStorage::value_type& lhs,
- const DictStorage::value_type& rhs) {
- if (lhs.first != rhs.first)
- return false;
-
- return lhs.second->Equals(rhs.second.get());
- });
- }
- case Type::LIST: {
- if (list_->size() != other->list_->size())
- return false;
-
- return std::equal(std::begin(*list_), std::end(*list_),
- std::begin(*(other->list_)),
- [](const ListStorage::value_type& lhs,
- const ListStorage::value_type& rhs) {
- return lhs->Equals(rhs.get());
- });
- }
- }
-
- NOTREACHED();
- return false;
+ DCHECK(other);
+ return *this == *other;
}
// static
bool Value::Equals(const Value* a, const Value* b) {
- if ((a == NULL) && (b == NULL)) return true;
- if ((a == NULL) ^ (b == NULL)) return false;
- return a->Equals(b);
+ if ((a == NULL) && (b == NULL))
+ return true;
+ if ((a == NULL) ^ (b == NULL))
+ return false;
+ return *a == *b;
}
void Value::InternalCopyFundamentalValue(const Value& that) {

Powered by Google App Engine
This is Rietveld 408576698