about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/primops
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/libexpr/primops
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/libexpr/primops')
-rw-r--r--third_party/nix/src/libexpr/primops/fetchGit.cc6
-rw-r--r--third_party/nix/src/libexpr/primops/fetchMercurial.cc14
2 files changed, 12 insertions, 8 deletions
diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc
index 99f1c3c4ba0c..2cfdefe7abfd 100644
--- a/third_party/nix/src/libexpr/primops/fetchGit.cc
+++ b/third_party/nix/src/libexpr/primops/fetchGit.cc
@@ -3,6 +3,7 @@
 
 #include <absl/strings/ascii.h>
 #include <absl/strings/match.h>
+#include <absl/strings/str_split.h>
 #include <glog/logging.h>
 #include <sys/time.h>
 
@@ -54,8 +55,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri,
       gitInfo.rev = "0000000000000000000000000000000000000000";
       gitInfo.shortRev = std::string(gitInfo.rev, 0, 7);
 
-      auto files = tokenizeString<std::set<std::string>>(
-          runProgram("git", true, {"-C", uri, "ls-files", "-z"}), "\0"s);
+      std::set<std::string> files =
+          absl::StrSplit(runProgram("git", true, {"-C", uri, "ls-files", "-z"}),
+                         absl::ByChar('\0'));
 
       PathFilter filter = [&](const Path& p) -> bool {
         assert(absl::StartsWith(p, uri));
diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
index b6d4a5e1c8bc..71722faedf11 100644
--- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc
+++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc
@@ -3,6 +3,7 @@
 
 #include <absl/strings/ascii.h>
 #include <absl/strings/match.h>
+#include <absl/strings/str_split.h>
 #include <glog/logging.h>
 #include <sys/time.h>
 
@@ -48,11 +49,11 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
       hgInfo.branch = absl::StripTrailingAsciiWhitespace(
           runProgram("hg", true, {"branch", "-R", uri}));
 
-      auto files = tokenizeString<std::set<std::string>>(
+      std::set<std::string> files = absl::StrSplit(
           runProgram("hg", true,
                      {"status", "-R", uri, "--clean", "--modified", "--added",
                       "--no-status", "--print0"}),
-          "\0"s);
+          absl::ByChar('\0'));
 
       PathFilter filter = [&](const Path& p) -> bool {
         assert(absl::StartsWith(p, uri));
@@ -124,10 +125,11 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri,
     writeFile(stampFile, "");
   }
 
-  auto tokens = tokenizeString<std::vector<std::string>>(
-      runProgram("hg", true,
-                 {"log", "-R", cacheDir, "-r", rev, "--template",
-                  "{node} {rev} {branch}"}));
+  std::vector<std::string> tokens =
+      absl::StrSplit(runProgram("hg", true,
+                                {"log", "-R", cacheDir, "-r", rev, "--template",
+                                 "{node} {rev} {branch}"}),
+                     absl::ByAnyChar(" \t\n\r"));
   assert(tokens.size() == 3);
 
   HgInfo hgInfo;