From bf452cbc2ae2b209ec262ce858deca470d086f24 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 25 May 2020 15:54:14 +0100 Subject: 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. --- third_party/nix/src/libexpr/primops/fetchGit.cc | 6 ++++-- third_party/nix/src/libexpr/primops/fetchMercurial.cc | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'third_party/nix/src/libexpr/primops') diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index 99f1c3c4ba..2cfdefe7ab 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -54,8 +55,9 @@ GitInfo exportGit(ref store, const std::string& uri, gitInfo.rev = "0000000000000000000000000000000000000000"; gitInfo.shortRev = std::string(gitInfo.rev, 0, 7); - auto files = tokenizeString>( - runProgram("git", true, {"-C", uri, "ls-files", "-z"}), "\0"s); + std::set 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 b6d4a5e1c8..71722faedf 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -48,11 +49,11 @@ HgInfo exportMercurial(ref store, const std::string& uri, hgInfo.branch = absl::StripTrailingAsciiWhitespace( runProgram("hg", true, {"branch", "-R", uri})); - auto files = tokenizeString>( + std::set 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, const std::string& uri, writeFile(stampFile, ""); } - auto tokens = tokenizeString>( - runProgram("hg", true, - {"log", "-R", cacheDir, "-r", rev, "--template", - "{node} {rev} {branch}"})); + std::vector 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; -- cgit 1.4.1