1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 20:01:15 +02:00

Bindings: Add a method for iterating in lexicographically sorted order

This commit is contained in:
Eelco Dolstra 2017-01-25 16:06:50 +01:00
parent b1f001538e
commit 54801ed6ad
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
4 changed files with 28 additions and 28 deletions

View file

@ -998,12 +998,9 @@ static void prim_attrNames(EvalState & state, const Pos & pos, Value * * args, V
state.mkList(v, args[0]->attrs->size());
unsigned int n = 0;
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; });
size_t n = 0;
for (auto & i : args[0]->attrs->lexicographicOrder())
mkString(*(v.listElems()[n++] = state.allocValue()), i->name);
}