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

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