diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-02-02 12:38:37 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-02-02 12:38:37 +0100 |
commit | cd35bbbeef72375873e396b9ffed14a4638693a8 (patch) | |
tree | 3db28adee43b34ce0875d27f21bab247a34e4586 /src/libstore | |
parent | 73d5f38a47e7c3dea62994cfb8f962976194f767 (diff) | |
parent | d439dceb3bc47f10a6f1f5b8cf4a5b17adc80071 (diff) |
Merge branch 'more-stringviews' of https://github.com/pennae/nix
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/derivations.cc | 4 | ||||
-rw-r--r-- | src/libstore/derivations.hh | 2 | ||||
-rw-r--r-- | src/libstore/names.cc | 24 | ||||
-rw-r--r-- | src/libstore/names.hh | 6 | ||||
-rw-r--r-- | src/libstore/optimise-store.cc | 9 | ||||
-rw-r--r-- | src/libstore/parsed-derivations.cc | 2 |
6 files changed, 24 insertions, 23 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 3e3d50144..40af6a775 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -699,10 +699,10 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr } -std::string hashPlaceholder(const std::string & outputName) +std::string hashPlaceholder(const std::string_view outputName) { // FIXME: memoize? - return "/" + hashString(htSHA256, "nix-output:" + outputName).to_string(Base32, false); + return "/" + hashString(htSHA256, concatStrings("nix-output:", outputName)).to_string(Base32, false); } std::string downstreamPlaceholder(const Store & store, const StorePath & drvPath, std::string_view outputName) diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index b1cb68194..a644cec60 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -236,7 +236,7 @@ void writeDerivation(Sink & out, const Store & store, const BasicDerivation & dr It is used as a placeholder to allow derivations to refer to their own outputs without needing to use the hash of a derivation in itself, making the hash near-impossible to calculate. */ -std::string hashPlaceholder(const std::string & outputName); +std::string hashPlaceholder(const std::string_view outputName); /* This creates an opaque and almost certainly unique string deterministically from a derivation path and output name. diff --git a/src/libstore/names.cc b/src/libstore/names.cc index 54c95055d..277aabf0f 100644 --- a/src/libstore/names.cc +++ b/src/libstore/names.cc @@ -56,8 +56,8 @@ bool DrvName::matches(const DrvName & n) } -string nextComponent(string::const_iterator & p, - const string::const_iterator end) +std::string_view nextComponent(std::string_view::const_iterator & p, + const std::string_view::const_iterator end) { /* Skip any dots and dashes (component separators). */ while (p != end && (*p == '.' || *p == '-')) ++p; @@ -67,18 +67,18 @@ string nextComponent(string::const_iterator & p, /* If the first character is a digit, consume the longest sequence of digits. Otherwise, consume the longest sequence of non-digit, non-separator characters. */ - string s; + auto s = p; if (isdigit(*p)) - while (p != end && isdigit(*p)) s += *p++; + while (p != end && isdigit(*p)) p++; else while (p != end && (!isdigit(*p) && *p != '.' && *p != '-')) - s += *p++; + p++; - return s; + return {s, size_t(p - s)}; } -static bool componentsLT(const string & c1, const string & c2) +static bool componentsLT(const std::string_view c1, const std::string_view c2) { auto n1 = string2Int<int>(c1); auto n2 = string2Int<int>(c2); @@ -94,14 +94,14 @@ static bool componentsLT(const string & c1, const string & c2) } -int compareVersions(const string & v1, const string & v2) +int compareVersions(const std::string_view v1, const std::string_view v2) { - string::const_iterator p1 = v1.begin(); - string::const_iterator p2 = v2.begin(); + auto p1 = v1.begin(); + auto p2 = v2.begin(); while (p1 != v1.end() || p2 != v2.end()) { - string c1 = nextComponent(p1, v1.end()); - string c2 = nextComponent(p2, v2.end()); + auto c1 = nextComponent(p1, v1.end()); + auto c2 = nextComponent(p2, v2.end()); if (componentsLT(c1, c2)) return -1; else if (componentsLT(c2, c1)) return 1; } diff --git a/src/libstore/names.hh b/src/libstore/names.hh index 3f861bc44..6f01fe2a1 100644 --- a/src/libstore/names.hh +++ b/src/libstore/names.hh @@ -27,9 +27,9 @@ private: typedef list<DrvName> DrvNames; -string nextComponent(string::const_iterator & p, - const string::const_iterator end); -int compareVersions(const string & v1, const string & v2); +std::string_view nextComponent(std::string_view::const_iterator & p, + const std::string_view::const_iterator end); +int compareVersions(const std::string_view v1, const std::string_view v2); DrvNames drvNamesFromArgs(const Strings & opArgs); } diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc index 1833c954e..13cb142f8 100644 --- a/src/libstore/optimise-store.cc +++ b/src/libstore/optimise-store.cc @@ -26,7 +26,7 @@ static void makeWritable(const Path & path) struct MakeReadOnly { Path path; - MakeReadOnly(const Path & path) : path(path) { } + MakeReadOnly(const PathView path) : path(path) { } ~MakeReadOnly() { try { @@ -205,12 +205,13 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats, /* Make the containing directory writable, but only if it's not the store itself (we don't want or need to mess with its permissions). */ - bool mustToggle = dirOf(path) != realStoreDir.get(); - if (mustToggle) makeWritable(dirOf(path)); + const Path dirOfPath(dirOf(path)); + bool mustToggle = dirOfPath != realStoreDir.get(); + if (mustToggle) makeWritable(dirOfPath); /* When we're done, make the directory read-only again and reset its timestamp back to 0. */ - MakeReadOnly makeReadOnly(mustToggle ? dirOf(path) : ""); + MakeReadOnly makeReadOnly(mustToggle ? dirOfPath : ""); Path tempLink = (format("%1%/.tmp-link-%2%-%3%") % realStoreDir % getpid() % random()).str(); diff --git a/src/libstore/parsed-derivations.cc b/src/libstore/parsed-derivations.cc index caddba9b1..8c65053e4 100644 --- a/src/libstore/parsed-derivations.cc +++ b/src/libstore/parsed-derivations.cc @@ -170,7 +170,7 @@ std::string writeStructuredAttrsShell(const nlohmann::json & json) auto handleSimpleType = [](const nlohmann::json & value) -> std::optional<std::string> { if (value.is_string()) - return shellEscape(value); + return shellEscape(value.get<std::string_view>()); if (value.is_number()) { auto f = value.get<float>(); |