You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/11/21 18:16:25 UTC

mesos git commit: Preallocated buffer for resources conversion.

Repository: mesos
Updated Branches:
  refs/heads/master d7bf06e80 -> b7ad2c0d4


Preallocated buffer for resources conversion.

When converting collections of protobuf `Resource` to `Resources`,
`std::vector` could be resized several times. This patch ensures that
there is enough capacity to fit all resources in `vector` and avoid
resizes.

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


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

Branch: refs/heads/master
Commit: b7ad2c0d4e7308a70049a6a04f19e3709df0e539
Parents: d7bf06e
Author: Dmitry Zhuk <dz...@twopensource.com>
Authored: Tue Nov 21 10:11:46 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Nov 21 10:11:46 2017 -0800

----------------------------------------------------------------------
 src/common/resources.cpp | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b7ad2c0d/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 4ccfdc1..2774372 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -1360,6 +1360,7 @@ Resources::Resources(const Resource& resource)
 
 Resources::Resources(const vector<Resource>& _resources)
 {
+  resources.reserve(_resources.size());
   foreach (const Resource& resource, _resources) {
     // NOTE: Invalid and zero Resource objects will be ignored.
     *this += resource;
@@ -1369,6 +1370,7 @@ Resources::Resources(const vector<Resource>& _resources)
 
 Resources::Resources(const RepeatedPtrField<Resource>& _resources)
 {
+  resources.reserve(_resources.size());
   foreach (const Resource& resource, _resources) {
     // NOTE: Invalid and zero Resource objects will be ignored.
     *this += resource;