about summary refs log tree commit diff
path: root/third_party/nix/src/libutil/util.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-20T21·58+0100
committerVincent Ambo <tazjin@google.com>2020-05-20T21·58+0100
commit43677021e3c285c2ced2075b918da947e13fcb00 (patch)
tree261d2ecbc6a9492d6410f9f4e8fd6629f20b49e6 /third_party/nix/src/libutil/util.cc
parent689ef502f5b0655c9923ed77da2ae3504630f473 (diff)
refactor(3p/nix): Apply clang-tidy's performance-* fixes r/789
This applies the performance fixes listed here:

https://clang.llvm.org/extra/clang-tidy/checks/list.html
Diffstat (limited to 'third_party/nix/src/libutil/util.cc')
-rw-r--r--third_party/nix/src/libutil/util.cc14
1 files changed, 7 insertions, 7 deletions
diff --git a/third_party/nix/src/libutil/util.cc b/third_party/nix/src/libutil/util.cc
index 21da06b8ab1e..b13dd7e4f975 100644
--- a/third_party/nix/src/libutil/util.cc
+++ b/third_party/nix/src/libutil/util.cc
@@ -76,9 +76,9 @@ void clearEnv() {
   }
 }
 
-void replaceEnv(std::map<std::string, std::string> newEnv) {
+void replaceEnv(const std::map<std::string, std::string>& newEnv) {
   clearEnv();
-  for (auto newEnvVar : newEnv) {
+  for (const auto& newEnvVar : newEnv) {
     setenv(newEnvVar.first.c_str(), newEnvVar.second.c_str(), 1);
   }
 }
@@ -888,9 +888,9 @@ void killUser(uid_t uid) {
 
 /* Wrapper around vfork to prevent the child process from clobbering
    the caller's stack frame in the parent. */
-static pid_t doFork(bool allowVfork, std::function<void()> fun)
+static pid_t doFork(bool allowVfork, const std::function<void()>& fun)
     __attribute__((noinline));
-static pid_t doFork(bool allowVfork, std::function<void()> fun) {
+static pid_t doFork(bool allowVfork, const std::function<void()>& fun) {
 #ifdef __linux__
   pid_t pid = allowVfork ? vfork() : fork();
 #else
@@ -944,7 +944,7 @@ std::vector<char*> stringsToCharPtrs(const Strings& ss) {
   return res;
 }
 
-string runProgram(Path program, bool searchPath, const Strings& args,
+string runProgram(const Path& program, bool searchPath, const Strings& args,
                   const std::optional<std::string>& input) {
   RunOptions opts(program, args);
   opts.searchPath = searchPath;
@@ -1425,7 +1425,7 @@ string base64Decode(const string& s) {
 }
 
 void callFailure(const std::function<void(std::exception_ptr exc)>& failure,
-                 std::exception_ptr exc) {
+                 const std::exception_ptr& exc) {
   try {
     failure(exc);
   } catch (std::exception& e) {
@@ -1516,7 +1516,7 @@ struct InterruptCallbackImpl : InterruptCallback {
 };
 
 std::unique_ptr<InterruptCallback> createInterruptCallback(
-    std::function<void()> callback) {
+    const std::function<void()>& callback) {
   auto interruptCallbacks(_interruptCallbacks.lock());
   interruptCallbacks->push_back(callback);