You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/05/09 08:30:08 UTC

mesos git commit: Cleaned up pattern matching in Resource operator==.

Repository: mesos
Updated Branches:
  refs/heads/master 188d2e220 -> 0f9180314


Cleaned up pattern matching in Resource operator==.

The usual pattern for checking optional fields here is to check
whether the field is is either set for both sides or unset for both.
Subsequentially we check if possible values are equal, returning
'false' if they are not.

The code changed here did not follow this pattern, but instead assumed
it was the last check to run. This made it possible that a careless
addition after these checks would never be called.

Review: https://reviews.apache.org/r/58136/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0f918031
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0f918031
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0f918031

Branch: refs/heads/master
Commit: 0f9180314d2f7b0bcbf1a5de2001d6e39f7eb8c4
Parents: 188d2e2
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Tue May 9 10:30:01 2017 +0200
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue May 9 10:30:01 2017 +0200

----------------------------------------------------------------------
 src/common/resources.cpp | 5 +++--
 src/v1/resources.cpp     | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0f918031/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 77bac0c..f6f02eb 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -203,8 +203,9 @@ bool operator==(const Resource::DiskInfo& left, const Resource::DiskInfo& right)
     return false;
   }
 
-  if (left.has_persistence()) {
-    return left.persistence().id() == right.persistence().id();
+  if (left.has_persistence() &&
+      left.persistence().id() != right.persistence().id()) {
+    return false;
   }
 
   return true;

http://git-wip-us.apache.org/repos/asf/mesos/blob/0f918031/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 2e6b298..cad069d 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -205,8 +205,9 @@ bool operator==(const Resource::DiskInfo& left, const Resource::DiskInfo& right)
     return false;
   }
 
-  if (left.has_persistence()) {
-    return left.persistence().id() == right.persistence().id();
+  if (left.has_persistence() &&
+      left.persistence().id() != right.persistence().id()) {
+    return false;
   }
 
   return true;