aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-01-12 18:17:59 +0100
committerpennae <github@quasiparticle.net>2022-01-13 14:00:19 +0100
commitef45787aae1c91dffce1e95db3d46740b0165319 (patch)
treeab42abf7cb043c9540d97a1a74bf8844db0d50a5 /src/libexpr/primops.cc
parent1bebb1095a122d4741c4ed9cd9cb19f08753872b (diff)
avoid string copies in attrNames sort comparison
symbols can also be cast to string_view, which compares the same but doesn't require a copy of both symbol names on every comparison.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 7b0e6e7df..365595c92 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -2163,7 +2163,10 @@ static void prim_attrValues(EvalState & state, const Pos & pos, Value * * args,
v.listElems()[n++] = (Value *) &i;
std::sort(v.listElems(), v.listElems() + n,
- [](Value * v1, Value * v2) { return (string) ((Attr *) v1)->name < (string) ((Attr *) v2)->name; });
+ [](Value * v1, Value * v2) {
+ std::string_view s1 = ((Attr *) v1)->name, s2 = ((Attr *) v2)->name;
+ return s1 < s2;
+ });
for (unsigned int i = 0; i < n; ++i)
v.listElems()[i] = ((Attr *) v.listElems()[i])->value;