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 2014/11/19 09:54:14 UTC

[9/9] mesos git commit: Eliminated the copying in Resource addition and subtraction.

Eliminated the copying in Resource addition and subtraction.

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


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

Branch: refs/heads/master
Commit: 0966e6ec4a101702388c1331f7af5ce35f26e4da
Parents: 550f5fc
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Nov 17 17:33:14 2014 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Nov 19 00:38:48 2014 -0800

----------------------------------------------------------------------
 src/common/resources.cpp | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0966e6ec/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 23fd6a3..61d16a8 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -115,13 +115,12 @@ bool operator != (const Resource& left, const Resource& right)
 
 Resource& operator += (Resource& left, const Resource& right)
 {
-  // TODO(jieyu): Leverage += for Value to avoid copying.
   if (left.type() == Value::SCALAR) {
-    left.mutable_scalar()->CopyFrom(left.scalar() + right.scalar());
+    *left.mutable_scalar() += right.scalar();
   } else if (left.type() == Value::RANGES) {
-    left.mutable_ranges()->CopyFrom(left.ranges() + right.ranges());
+    *left.mutable_ranges() += right.ranges();
   } else if (left.type() == Value::SET) {
-    left.mutable_set()->CopyFrom(left.set() + right.set());
+    *left.mutable_set() += right.set();
   }
 
   return left;
@@ -138,13 +137,12 @@ Resource operator + (const Resource& left, const Resource& right)
 
 Resource& operator -= (Resource& left, const Resource& right)
 {
-  // TODO(jieyu): Leverage -= for Value to avoid copying.
   if (left.type() == Value::SCALAR) {
-    left.mutable_scalar()->CopyFrom(left.scalar() - right.scalar());
+    *left.mutable_scalar() -= right.scalar();
   } else if (left.type() == Value::RANGES) {
-    left.mutable_ranges()->CopyFrom(left.ranges() - right.ranges());
+    *left.mutable_ranges() -= right.ranges();
   } else if (left.type() == Value::SET) {
-    left.mutable_set()->CopyFrom(left.set() - right.set());
+    *left.mutable_set() -= right.set();
   }
 
   return left;