diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-25T14·54+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-25T14·54+0100 |
commit | bf452cbc2ae2b209ec262ce858deca470d086f24 (patch) | |
tree | 198e98902be569301ecb9a821b0c9512b128f930 /third_party/nix/src/libstore/derivations.cc | |
parent | b99b368d17f2e806a61f7abb83c6d3a9e4bbdc38 (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/derivations.cc')
-rw-r--r-- | third_party/nix/src/libstore/derivations.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/third_party/nix/src/libstore/derivations.cc b/third_party/nix/src/libstore/derivations.cc index 9f2aa5ea924f..b2590f5e28e6 100644 --- a/third_party/nix/src/libstore/derivations.cc +++ b/third_party/nix/src/libstore/derivations.cc @@ -1,6 +1,8 @@ #include "derivations.hh" #include <absl/strings/match.h> +#include <absl/strings/str_split.h> +#include <absl/strings/string_view.h> #include "fs-accessor.hh" #include "globals.hh" @@ -357,13 +359,15 @@ Hash hashDerivationModulo(Store& store, Derivation drv) { return hashString(htSHA256, drv.unparse()); } -DrvPathWithOutputs parseDrvPathWithOutputs(const std::string& s) { - size_t n = s.find('!'); - return n == std::string::npos - ? DrvPathWithOutputs(s, std::set<std::string>()) - : DrvPathWithOutputs(std::string(s, 0, n), - tokenizeString<std::set<std::string> >( - std::string(s, n + 1), ",")); +// TODO(tazjin): doc comment? +DrvPathWithOutputs parseDrvPathWithOutputs(absl::string_view path) { + auto pos = path.find('!'); + if (pos == absl::string_view::npos) { + return DrvPathWithOutputs(path, std::set<std::string>()); + } + + return DrvPathWithOutputs(path.substr(pos + 1), + absl::StrSplit(path, absl::ByChar(','))); } Path makeDrvPathWithOutputs(const Path& drvPath, |