diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-23T05·17+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-23T05·18+0100 |
commit | 3b903193beae1dee43a62ceaf9e48d6408386589 (patch) | |
tree | 2f7ed4056f24cfd2bead88871e37e24def333d1a | |
parent | 811c42d255b80b54f1d2f310f2673fa69c1be444 (diff) |
fix(3p/nix/libexpr): Fix attrNames/attrValues builtins for btree_map r/823
Replaces the previous implementations which performed sorting with one that instead walks through the map (which is already sorted) and yields values from it. This fixes a handful of language tests because the previous implementation did not actually yield useful values on the new implementation.
-rw-r--r-- | third_party/nix/src/libexpr/primops.cc | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 713c31e4fa79..5a9f1fe72076 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -1263,35 +1263,23 @@ static void prim_attrNames(EvalState& state, const Pos& pos, Value** args, state.mkList(v, args[0]->attrs->size()); - size_t n = 0; - for (auto& i : *args[0]->attrs) { - mkString(*(v.listElems()[n++] = state.allocValue()), i.second.name); + unsigned int n = 0; + for (auto& [key, value] : *args[0]->attrs) { + mkString(*(v.listElems()[n++] = state.allocValue()), key); } - - std::sort(v.listElems(), v.listElems() + n, [](Value* v1, Value* v2) { - return strcmp(v1->string.s, v2->string.s) < 0; - }); } /* Return the values of the attributes in a set as a list, in the same order as attrNames. */ -static void prim_attrValues(EvalState& state, const Pos& pos, Value** args, - Value& v) { - state.forceAttrs(*args[0], pos); +static void prim_attrValues(EvalState& state, const Pos& pos, Value** input, + Value& output) { + state.forceAttrs(*input[0], pos); - state.mkList(v, args[0]->attrs->size()); + state.mkList(output, input[0]->attrs->size()); unsigned int n = 0; - for (auto& i : *args[0]->attrs) { - 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; - }); - - for (unsigned int i = 0; i < n; ++i) { - v.listElems()[i] = ((Attr*)v.listElems()[i])->value; + for (auto& [key, value] : *input[0]->attrs) { + output.listElems()[n++] = value.value; } } |