Avoid redundant copies when using `std::get` on a tuple.

`std::get` returns a reference; in most cases we can avoid a copy at the
call site by assigning the result to a const reference.

Spotted using the "performance-unnecessary-copy-initialization"
clang-tidy check.

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


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

Branch: refs/heads/master
Commit: 080e1b7eb10c4d455118c4ef8c7a3617a50fba89
Parents: c550d13
Author: Neil Conway <[email protected]>
Authored: Tue Mar 14 11:51:31 2017 -0700
Committer: Neil Conway <[email protected]>
Committed: Thu Mar 30 09:51:54 2017 -0700

----------------------------------------------------------------------
 src/checks/checker.cpp                              |  6 +++---
 src/checks/health_checker.cpp                       | 10 +++++-----
 src/common/command_utils.cpp                        |  6 +++---
 src/hdfs/hdfs.cpp                                   |  6 +++---
 src/linux/perf.cpp                                  |  4 ++--
 .../mesos/isolators/docker/volume/driver.cpp        | 10 +++++-----
 .../mesos/isolators/network/cni/cni.cpp             | 16 ++++++++--------
 .../network/cni/plugins/port_mapper/port_mapper.cpp |  6 +++---
 .../containerizer/mesos/isolators/posix/disk.cpp    |  6 +++---
 src/uri/fetchers/copy.cpp                           |  4 ++--
 src/uri/fetchers/curl.cpp                           |  6 +++---
 src/uri/fetchers/docker.cpp                         | 12 ++++++------
 12 files changed, 46 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/checks/checker.cpp
----------------------------------------------------------------------
diff --git a/src/checks/checker.cpp b/src/checks/checker.cpp
index 314354c..3f2d8d8 100644
--- a/src/checks/checker.cpp
+++ b/src/checks/checker.cpp
@@ -541,7 +541,7 @@ Future<int> CheckerProcess::_httpCheck(
         Future<string>,
         Future<string>>& t)
 {
-  Future<Option<int>> status = std::get<0>(t);
+  const Future<Option<int>>& status = std::get<0>(t);
   if (!status.isReady()) {
     return Failure(
         "Failed to get the exit status of the " + string(HTTP_CHECK_COMMAND) +
@@ -555,7 +555,7 @@ Future<int> CheckerProcess::_httpCheck(
 
   int exitCode = status->get();
   if (exitCode != 0) {
-    Future<string> error = std::get<2>(t);
+    const Future<string>& error = std::get<2>(t);
     if (!error.isReady()) {
       return Failure(
           string(HTTP_CHECK_COMMAND) + " returned " +
@@ -568,7 +568,7 @@ Future<int> CheckerProcess::_httpCheck(
         WSTRINGIFY(exitCode) + ": " + error.get());
   }
 
-  Future<string> output = std::get<1>(t);
+  const Future<string>& output = std::get<1>(t);
   if (!output.isReady()) {
     return Failure(
         "Failed to read stdout from " + string(HTTP_CHECK_COMMAND) + ": " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/checks/health_checker.cpp
----------------------------------------------------------------------
diff --git a/src/checks/health_checker.cpp b/src/checks/health_checker.cpp
index 2211228..b768c5b 100644
--- a/src/checks/health_checker.cpp
+++ b/src/checks/health_checker.cpp
@@ -880,7 +880,7 @@ Future<Nothing> HealthCheckerProcess::_httpHealthCheck(
         Future<string>,
         Future<string>>& t)
 {
-  Future<Option<int>> status = std::get<0>(t);
+  const Future<Option<int>>& status = std::get<0>(t);
   if (!status.isReady()) {
     return Failure(
         "Failed to get the exit status of the " + string(HTTP_CHECK_COMMAND) +
@@ -894,7 +894,7 @@ Future<Nothing> HealthCheckerProcess::_httpHealthCheck(
 
   int statusCode = status->get();
   if (statusCode != 0) {
-    Future<string> error = std::get<2>(t);
+    const Future<string>& error = std::get<2>(t);
     if (!error.isReady()) {
       return Failure(
           string(HTTP_CHECK_COMMAND) + " returned " +
@@ -907,7 +907,7 @@ Future<Nothing> HealthCheckerProcess::_httpHealthCheck(
         WSTRINGIFY(statusCode) + ": " + error.get());
   }
 
-  Future<string> output = std::get<1>(t);
+  const Future<string>& output = std::get<1>(t);
   if (!output.isReady()) {
     return Failure(
         "Failed to read stdout from " + string(HTTP_CHECK_COMMAND) + ": " +
@@ -1006,7 +1006,7 @@ Future<Nothing> HealthCheckerProcess::_tcpHealthCheck(
         Future<string>,
         Future<string>>& t)
 {
-  Future<Option<int>> status = std::get<0>(t);
+  const Future<Option<int>>& status = std::get<0>(t);
   if (!status.isReady()) {
     return Failure(
         "Failed to get the exit status of the " + string(TCP_CHECK_COMMAND) +
@@ -1020,7 +1020,7 @@ Future<Nothing> HealthCheckerProcess::_tcpHealthCheck(
 
   int statusCode = status->get();
   if (statusCode != 0) {
-    Future<string> error = std::get<2>(t);
+    const Future<string>& error = std::get<2>(t);
     if (!error.isReady()) {
       return Failure(
           string(TCP_CHECK_COMMAND) + " returned " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/common/command_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/command_utils.cpp b/src/common/command_utils.cpp
index cb9de72..d5f0dff 100644
--- a/src/common/command_utils.cpp
+++ b/src/common/command_utils.cpp
@@ -70,7 +70,7 @@ static Future<string> launch(
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<string> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the subprocess: " +
@@ -82,7 +82,7 @@ static Future<string> launch(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<2>(t);
+        const Future<string>& error = std::get<2>(t);
         if (!error.isReady()) {
             return Failure(
                 "Unexpected result from the subprocess: " +
@@ -93,7 +93,7 @@ static Future<string> launch(
         return Failure("Subprocess '" + command + "' failed: " + error.get());
       }
 
-      Future<string> output = std::get<1>(t);
+      const Future<string>& output = std::get<1>(t);
       if (!output.isReady()) {
          return Failure(
             "Failed to read stdout from '" + command + "': " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/hdfs/hdfs.cpp
----------------------------------------------------------------------
diff --git a/src/hdfs/hdfs.cpp b/src/hdfs/hdfs.cpp
index 93450b9..2c95a5e 100644
--- a/src/hdfs/hdfs.cpp
+++ b/src/hdfs/hdfs.cpp
@@ -65,21 +65,21 @@ static Future<CommandResult> result(const Subprocess& s)
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<CommandResult> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the subprocess: " +
             (status.isFailed() ? status.failure() : "discarded"));
       }
 
-      Future<string> output = std::get<1>(t);
+      const Future<string>& output = std::get<1>(t);
       if (!output.isReady()) {
         return Failure(
             "Failed to read stdout from the subprocess: " +
             (output.isFailed() ? output.failure() : "discarded"));
       }
 
-      Future<string> error = std::get<2>(t);
+      const Future<string>& error = std::get<2>(t);
       if (!error.isReady()) {
         return Failure(
             "Failed to read stderr from the subprocess: " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/linux/perf.cpp
----------------------------------------------------------------------
diff --git a/src/linux/perf.cpp b/src/linux/perf.cpp
index 2271564..5f4f50a 100644
--- a/src/linux/perf.cpp
+++ b/src/linux/perf.cpp
@@ -154,8 +154,8 @@ private:
           Future<Option<int>>,
           Future<string>,
           Future<string>>& results) {
-        Future<Option<int>> status = std::get<0>(results);
-        Future<string> output = std::get<1>(results);
+        const Future<Option<int>>& status = std::get<0>(results);
+        const Future<string>& output = std::get<1>(results);
 
         Option<Error> error = None();
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/slave/containerizer/mesos/isolators/docker/volume/driver.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/docker/volume/driver.cpp 
b/src/slave/containerizer/mesos/isolators/docker/volume/driver.cpp
index 8cc1b12..18a8066 100644
--- a/src/slave/containerizer/mesos/isolators/docker/volume/driver.cpp
+++ b/src/slave/containerizer/mesos/isolators/docker/volume/driver.cpp
@@ -107,7 +107,7 @@ Future<string> DriverClient::mount(
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<string> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the subprocess: " +
@@ -119,7 +119,7 @@ Future<string> DriverClient::mount(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<2>(t);
+        const Future<string>& error = std::get<2>(t);
         if (!error.isReady()) {
           return Failure(
               "Unexpected termination of the subprocess: " +
@@ -130,7 +130,7 @@ Future<string> DriverClient::mount(
             "Unexpected termination of the subprocess: " + error.get());
       }
 
-      Future<string> output = std::get<1>(t);
+      const Future<string>& output = std::get<1>(t);
       if (!output.isReady()) {
          return Failure(
             "Failed to read stdout from the subprocess: " +
@@ -189,7 +189,7 @@ Future<Nothing> DriverClient::unmount(
     .then([](const tuple<
         Future<Option<int>>,
         Future<string>>& t) -> Future<Nothing> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the subprocess: " +
@@ -201,7 +201,7 @@ Future<Nothing> DriverClient::unmount(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<1>(t);
+        const Future<string>& error = std::get<1>(t);
         if (!error.isReady()) {
           return Failure(
             "Unexpected termination of the subprocess: " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp 
b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
index 6e95315..d03c14c 100644
--- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
+++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp
@@ -1063,7 +1063,7 @@ Future<Nothing> NetworkCniIsolatorProcess::__isolate(
     .then([](const tuple<
         Future<Option<int>>,
         Future<string>>& t) -> Future<Nothing> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the setup helper subprocess: " +
@@ -1074,7 +1074,7 @@ Future<Nothing> NetworkCniIsolatorProcess::__isolate(
         return Failure("Failed to reap the setup helper subprocess");
       }
 
-      Future<string> err = std::get<1>(t);
+      const Future<string>& err = std::get<1>(t);
       if (!err.isReady()) {
         return Failure(
             "Failed to read stderr from the helper subprocess: " +
@@ -1251,7 +1251,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_attach(
   CHECK(infos.contains(containerId));
   CHECK(infos[containerId]->containerNetworks.contains(networkName));
 
-  Future<Option<int>> status = std::get<0>(t);
+  const Future<Option<int>>& status = std::get<0>(t);
   if (!status.isReady()) {
     return Failure(
         "Failed to get the exit status of the CNI plugin '" +
@@ -1266,7 +1266,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_attach(
 
   // CNI plugin will print result (in case of success) or error (in
   // case of failure) to stdout.
-  Future<string> output = std::get<1>(t);
+  const Future<string>& output = std::get<1>(t);
   if (!output.isReady()) {
     return Failure(
         "Failed to read stdout from the CNI plugin '" +
@@ -1275,7 +1275,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_attach(
   }
 
   if (status.get() != 0) {
-    Future<string> error = std::get<2>(t);
+    const Future<string>& error = std::get<2>(t);
     if (!error.isReady()) {
       return Failure(
           "Failed to read stderr from the CNI plugin '" +
@@ -1607,7 +1607,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_detach(
   CHECK(infos.contains(containerId));
   CHECK(infos[containerId]->containerNetworks.contains(networkName));
 
-  Future<Option<int>> status = std::get<0>(t);
+  const Future<Option<int>>& status = std::get<0>(t);
   if (!status.isReady()) {
     return Failure(
         "Failed to get the exit status of the CNI plugin '" +
@@ -1637,7 +1637,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_detach(
     return Nothing();
   }
 
-  Future<string> output = std::get<1>(t);
+  const Future<string>& output = std::get<1>(t);
   if (!output.isReady()) {
     return Failure(
         "Failed to read stdout from the CNI plugin '" +
@@ -1645,7 +1645,7 @@ Future<Nothing> NetworkCniIsolatorProcess::_detach(
         (output.isFailed() ? output.failure() : "discarded"));
   }
 
-  Future<string> error = std::get<2>(t);
+  const Future<string>& error = std::get<2>(t);
   if (!error.isReady()) {
     return Failure(
         "Failed to read stderr from the CNI plugin '" +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
index 1be8c23..d419a9f 100644
--- 
a/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
+++ 
b/src/slave/containerizer/mesos/isolators/network/cni/plugins/port_mapper/port_mapper.cpp
@@ -560,7 +560,7 @@ Result<spec::NetworkInfo> PortMapper::delegate(const 
string& command)
         (result.isDiscarded() ? "discarded" : result.failure()));
   }
 
-  Future<Option<int>> status = std::get<0>(result.get());
+  const Future<Option<int>>& status = std::get<0>(result.get());
   if (!status.isReady()) {
     return Error(
         "Failed to get the exit status of the delegate CNI plugin '" +
@@ -575,7 +575,7 @@ Result<spec::NetworkInfo> PortMapper::delegate(const 
string& command)
   }
 
   // CNI plugin will print result or error to stdout.
-  Future<string> output = std::get<1>(result.get());
+  const Future<string>& output = std::get<1>(result.get());
   if (!output.isReady()) {
     return Error(
         "Failed to read stdout from the delegate CNI plugin '" +
@@ -586,7 +586,7 @@ Result<spec::NetworkInfo> PortMapper::delegate(const 
string& command)
   // We are reading stderr of the plugin since any log messages from
   // the CNI plugin would be thrown on stderr. This can be useful for
   // debugging issues when the plugin throws a `spec::Error`.
-  Future<string> err = std::get<2>(result.get());
+  const Future<string>& err = std::get<2>(result.get());
   if (!err.isReady()) {
     return Error(
         "Failed to read STDERR from the delegate CNI plugin '" +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/slave/containerizer/mesos/isolators/posix/disk.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/posix/disk.cpp 
b/src/slave/containerizer/mesos/isolators/posix/disk.cpp
index 805566c..127f490 100644
--- a/src/slave/containerizer/mesos/isolators/posix/disk.cpp
+++ b/src/slave/containerizer/mesos/isolators/posix/disk.cpp
@@ -579,7 +579,7 @@ private:
     const Owned<Entry>& entry = entries.front();
     CHECK_SOME(entry->du);
 
-    Future<Option<int>> status = std::get<0>(future.get());
+    const Future<Option<int>>& status = std::get<0>(future.get());
 
     if (!status.isReady()) {
       entry->promise.fail(
@@ -588,7 +588,7 @@ private:
     } else if (status.get().isNone()) {
       entry->promise.fail("Failed to reap the status of 'du'");
     } else if (status.get().get() != 0) {
-      Future<string> error = std::get<2>(future.get());
+      const Future<string>& error = std::get<2>(future.get());
       if (!error.isReady()) {
         entry->promise.fail(
             "Failed to perform 'du'. Reading stderr failed: " +
@@ -597,7 +597,7 @@ private:
         entry->promise.fail("Failed to perform 'du': " + error.get());
       }
     } else {
-      Future<string> output = std::get<1>(future.get());
+      const Future<string>& output = std::get<1>(future.get());
       if (!output.isReady()) {
         entry->promise.fail(
             "Failed to read stdout from 'du': " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/uri/fetchers/copy.cpp
----------------------------------------------------------------------
diff --git a/src/uri/fetchers/copy.cpp b/src/uri/fetchers/copy.cpp
index 9c79ac6..86605a0 100644
--- a/src/uri/fetchers/copy.cpp
+++ b/src/uri/fetchers/copy.cpp
@@ -116,7 +116,7 @@ Future<Nothing> CopyFetcherPlugin::fetch(
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<Nothing> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the copy subprocess: " +
@@ -128,7 +128,7 @@ Future<Nothing> CopyFetcherPlugin::fetch(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<2>(t);
+        const Future<string>& error = std::get<2>(t);
         if (!error.isReady()) {
           return Failure(
               "Failed to perform 'copy'. Reading stderr failed: " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/uri/fetchers/curl.cpp
----------------------------------------------------------------------
diff --git a/src/uri/fetchers/curl.cpp b/src/uri/fetchers/curl.cpp
index a592eb5..24b53c7 100644
--- a/src/uri/fetchers/curl.cpp
+++ b/src/uri/fetchers/curl.cpp
@@ -126,7 +126,7 @@ Future<Nothing> CurlFetcherPlugin::fetch(
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<Nothing> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the curl subprocess: " +
@@ -138,7 +138,7 @@ Future<Nothing> CurlFetcherPlugin::fetch(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<2>(t);
+        const Future<string>& error = std::get<2>(t);
         if (!error.isReady()) {
           return Failure(
               "Failed to perform 'curl'. Reading stderr failed: " +
@@ -148,7 +148,7 @@ Future<Nothing> CurlFetcherPlugin::fetch(
         return Failure("Failed to perform 'curl': " + error.get());
       }
 
-      Future<string> output = std::get<1>(t);
+      const Future<string>& output = std::get<1>(t);
       if (!output.isReady()) {
         return Failure(
             "Failed to read stdout from 'curl': " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/080e1b7e/src/uri/fetchers/docker.cpp
----------------------------------------------------------------------
diff --git a/src/uri/fetchers/docker.cpp b/src/uri/fetchers/docker.cpp
index d051a4d..d6d2e8e 100644
--- a/src/uri/fetchers/docker.cpp
+++ b/src/uri/fetchers/docker.cpp
@@ -131,7 +131,7 @@ static Future<http::Response> curl(
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<http::Response> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the curl subprocess: " +
@@ -143,7 +143,7 @@ static Future<http::Response> curl(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<2>(t);
+        const Future<string>& error = std::get<2>(t);
         if (!error.isReady()) {
           return Failure(
               "Failed to perform 'curl'. Reading stderr failed: " +
@@ -153,7 +153,7 @@ static Future<http::Response> curl(
         return Failure("Failed to perform 'curl': " + error.get());
       }
 
-      Future<string> output = std::get<1>(t);
+      const Future<string>& output = std::get<1>(t);
       if (!output.isReady()) {
         return Failure(
             "Failed to read stdout from 'curl': " +
@@ -249,7 +249,7 @@ static Future<int> download(
         Future<Option<int>>,
         Future<string>,
         Future<string>>& t) -> Future<int> {
-      Future<Option<int>> status = std::get<0>(t);
+      const Future<Option<int>>& status = std::get<0>(t);
       if (!status.isReady()) {
         return Failure(
             "Failed to get the exit status of the curl subprocess: " +
@@ -261,7 +261,7 @@ static Future<int> download(
       }
 
       if (status->get() != 0) {
-        Future<string> error = std::get<2>(t);
+        const Future<string>& error = std::get<2>(t);
         if (!error.isReady()) {
           return Failure(
               "Failed to perform 'curl'. Reading stderr failed: " +
@@ -271,7 +271,7 @@ static Future<int> download(
         return Failure("Failed to perform 'curl': " + error.get());
       }
 
-      Future<string> output = std::get<1>(t);
+      const Future<string>& output = std::get<1>(t);
       if (!output.isReady()) {
         return Failure(
             "Failed to read stdout from 'curl': " +

Reply via email to