about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/builtins/buildenv.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-25T14·54+0100
committerVincent Ambo <tazjin@google.com>2020-05-25T14·54+0100
commitbf452cbc2ae2b209ec262ce858deca470d086f24 (patch)
tree198e98902be569301ecb9a821b0c9512b128f930 /third_party/nix/src/libstore/builtins/buildenv.cc
parentb99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 (diff)
refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit r/846
This function was a custom (and inefficient in the case of
single-character delimiters) string splitter which was used all over
the codebase. Abseil provides an appropriate replacement function.
Diffstat (limited to 'third_party/nix/src/libstore/builtins/buildenv.cc')
-rw-r--r--third_party/nix/src/libstore/builtins/buildenv.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/third_party/nix/src/libstore/builtins/buildenv.cc b/third_party/nix/src/libstore/builtins/buildenv.cc
index 92cf2f8c1eec..db093663bfef 100644
--- a/third_party/nix/src/libstore/builtins/buildenv.cc
+++ b/third_party/nix/src/libstore/builtins/buildenv.cc
@@ -1,6 +1,7 @@
 #include <algorithm>
 
 #include <absl/strings/match.h>
+#include <absl/strings/str_split.h>
 #include <fcntl.h>
 #include <glog/logging.h>
 #include <sys/stat.h>
@@ -134,12 +135,14 @@ static void addPkg(const Path& pkgDir, int priority) {
   createLinks(pkgDir, out, priority);
 
   try {
-    for (const auto& p : tokenizeString<std::vector<std::string>>(
+    for (auto p : absl::StrSplit(
              readFile(pkgDir + "/nix-support/propagated-user-env-packages"),
-             " \n"))
-      if (!done.count(p)) {
-        postponed.insert(p);
+             absl::ByAnyChar(" \n"))) {
+      auto pkg = std::string(p);
+      if (!done.count(pkg)) {
+        postponed.insert(pkg);
       }
+    }
   } catch (SysError& e) {
     if (e.errNo != ENOENT && e.errNo != ENOTDIR) {
       throw;
@@ -172,7 +175,8 @@ void builtinBuildenv(const BasicDerivation& drv) {
   /* Convert the stuff we get from the environment back into a
    * coherent data type. */
   Packages pkgs;
-  auto derivations = tokenizeString<Strings>(getAttr("derivations"));
+  Strings derivations =
+      absl::StrSplit(getAttr("derivations"), absl::ByAnyChar(" \t\n\r"));
   while (!derivations.empty()) {
     /* !!! We're trusting the caller to structure derivations env var correctly
      */