aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/names.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-03-10 17:03:16 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2022-03-10 17:10:15 +0000
commite5c42bba9bf76d00fb15ec9a179bf91aa81c38c6 (patch)
tree7597549f36313859d15cb4ae80c04af955c9a223 /src/libstore/names.cc
parent1ef88da3503b88f289a15786dfd48821cf5b6502 (diff)
parent4d98143914120d0163f5c50f30ce8a5289433f8f (diff)
Merge remote-tracking branch 'upstream/master' into indexed-store-path-outputs
Diffstat (limited to 'src/libstore/names.cc')
-rw-r--r--src/libstore/names.cc26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/libstore/names.cc b/src/libstore/names.cc
index ce808accc..277aabf0f 100644
--- a/src/libstore/names.cc
+++ b/src/libstore/names.cc
@@ -42,7 +42,7 @@ DrvName::~DrvName()
{ }
-bool DrvName::matches(DrvName & n)
+bool DrvName::matches(const DrvName & n)
{
if (name != "*") {
if (!regex) {
@@ -56,8 +56,8 @@ bool DrvName::matches(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;
}