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/10/09 21:45:18 UTC
[2/3] mesos git commit: Fixed 'operator==' for
'v1::Resource::DiskInfo::Source'.
Fixed 'operator==' for 'v1::Resource::DiskInfo::Source'.
When implementing 'operator==' for protobufs as a pattern we typically
first check that two 'optional' fields are set for both the left- and
right-hand side, and only then compare their values, e.g., given a
definition
message Foo {
optional string bar = 1;
}
we would implement 'operator==' similar to the following,
bool operator==(const Foo& lhs, const Foo& rhs)
{
if (lhs.has_bar() != rhs.has_bar()) {
return false;
}
if (lhs.has_bar() && lhs.bar() != rhs.bar()) {
return false;
}
return true;
}
One reason for this is that it allows us to distinguish an unset field
from a set field containing a default constructed value (if e.g.,
above 'lhs.has_bar()' was 'false', 'lhs.bar()' would return an empty
string).
This patch makes sure we use the same pattern when checking
'v1::Resource::DiskInfo::Source' for equality. An earlier patch
('591f74d') already fixed this for 'Resources::DiskInfo::Source'.
Review: https://reviews.apache.org/r/62842/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/52079854
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/52079854
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/52079854
Branch: refs/heads/master
Commit: 5207985400a9135f85f9340bd679cc7d12ebec4d
Parents: 07f8da2
Author: Benjamin Bannier <bb...@apache.org>
Authored: Mon Oct 9 14:30:39 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Oct 9 14:45:05 2017 -0700
----------------------------------------------------------------------
src/v1/resources.cpp | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/52079854/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index a64180b..04df4d4 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -174,18 +174,34 @@ bool operator==(
return false;
}
+ if (left.has_path() != right.has_path()) {
+ return false;
+ }
+
if (left.has_path() && left.path() != right.path()) {
return false;
}
+ if (left.has_mount() != right.has_mount()) {
+ return false;
+ }
+
if (left.has_mount() && left.mount() != right.mount()) {
return false;
}
+ if (left.has_id() != right.has_id()) {
+ return false;
+ }
+
if (left.has_id() && left.id() != right.id()) {
return false;
}
+ if (left.has_metadata() != right.has_metadata()) {
+ return false;
+ }
+
if (left.has_metadata() && left.metadata() != right.metadata()) {
return false;
}