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

Unified Diff: base/values.cc

Issue 2740373002: Cleaning up base::Value assignment. (Closed)
Patch Set: Removing check for self-assignment. 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
« 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 5cc0d693bdd11c12e60f14f8921bec3cd303e4da..477d38291177b1537ae793cfbf3a1b287055455e 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -173,26 +173,24 @@ Value::Value(std::vector<char>&& in_blob) : type_(Type::BINARY) {
}
Value& Value::operator=(const Value& that) {
- if (this != &that) {
- if (type_ == that.type_) {
- InternalCopyAssignFromSameType(that);
- } else {
- InternalCleanup();
- InternalCopyConstructFrom(that);
- }
+ if (type_ == that.type_) {
+ InternalCopyAssignFromSameType(that);
+ } else {
+ // this is not a self assignment because the type_ doesn't match.
+ InternalCleanup();
+ InternalCopyConstructFrom(that);
}
return *this;
}
Value& Value::operator=(Value&& that) {
- if (this != &that) {
- if (type_ == that.type_) {
- InternalMoveAssignFromSameType(std::move(that));
- } else {
- InternalCleanup();
- InternalMoveConstructFrom(std::move(that));
- }
+ if (type_ == that.type_) {
+ DCHECK(this != &that) << " attempt to self move assign.";
+ InternalMoveAssignFromSameType(std::move(that));
dcheng 2017/03/10 18:40:15 We should just remove the branch entirely if we're
dyaroshev 2017/03/10 18:54:57 Done. std::variant (http://en.cppreference.com/w/c
+ } else {
+ InternalCleanup();
+ InternalMoveConstructFrom(std::move(that));
}
return *this;
« 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