refactor(3p/nix): Replace tokenizeStrings with absl::StrSplit

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.
This commit is contained in:
Vincent Ambo 2020-05-25 15:54:14 +01:00
parent b99b368d17
commit bf452cbc2a
29 changed files with 146 additions and 145 deletions

View file

@ -4,6 +4,7 @@
#include <cstring>
#include <regex>
#include <absl/strings/str_split.h>
#include <dlfcn.h>
#include <glog/logging.h>
#include <sys/stat.h>
@ -712,7 +713,7 @@ static void prim_derivationStrict(EvalState& state, const Pos& pos,
} else if (i->name == state.sOutputHashMode) {
handleHashMode(s);
} else if (i->name == state.sOutputs) {
handleOutputs(tokenizeString<Strings>(s));
handleOutputs(absl::StrSplit(s, absl::ByAnyChar(" \t\n\r")));
}
}
}

View file

@ -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));

View file

@ -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;