diff options
author | Tuomas Tynkkynen <tuomas@tuxera.com> | 2018-02-16 05:14:35 +0200 |
---|---|---|
committer | Tuomas Tynkkynen <tuomas@tuxera.com> | 2018-02-17 16:54:21 +0200 |
commit | b8bed7da14b26dcc328075522842dd16aa71b434 (patch) | |
tree | 3a40e0e284b61117b6fb797fbc23f6f58c0d7436 /src/libexpr/primops.cc | |
parent | f67a7007a230c84015793794277c0449e682ab54 (diff) |
libexpr: Optimize prim_attrNames a bit
Instead of having lexicographicOrder() create a temporary sorted array
of Attr*:s and copying attr names from that, copy the attr names
first and then sort that.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ca97b2b28..89e984d2e 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1138,8 +1138,11 @@ static void prim_attrNames(EvalState & state, const Pos & pos, Value * * args, V state.mkList(v, args[0]->attrs->size()); size_t n = 0; - for (auto & i : args[0]->attrs->lexicographicOrder()) - mkString(*(v.listElems()[n++] = state.allocValue()), i->name); + for (auto & i : *args[0]->attrs) + mkString(*(v.listElems()[n++] = state.allocValue()), i.name); + + std::sort(v.listElems(), v.listElems() + n, + [](Value * v1, Value * v2) { return strcmp(v1->string.s, v2->string.s) < 0; }); } |