attrNames: Don't allocate duplicates of the symbols
This commit is contained in:
parent
ea525a261f
commit
2d6cd8aafd
|
@ -914,13 +914,11 @@ static void prim_attrNames(EvalState & state, const Pos & pos, Value * * args, V
|
||||||
|
|
||||||
state.mkList(v, args[0]->attrs->size());
|
state.mkList(v, args[0]->attrs->size());
|
||||||
|
|
||||||
StringSet names;
|
|
||||||
foreach (Bindings::iterator, i, *args[0]->attrs)
|
|
||||||
names.insert(i->name);
|
|
||||||
|
|
||||||
unsigned int n = 0;
|
unsigned int n = 0;
|
||||||
foreach (StringSet::iterator, i, names)
|
for (auto & i : *args[0]->attrs)
|
||||||
mkString(*(v.list.elems[n++] = state.allocValue()), *i);
|
mkString(*(v.list.elems[n++] = state.allocValue()), i.name);
|
||||||
|
|
||||||
|
std::sort(v.list.elems, v.list.elems + n, [](Value * v1, Value * v2) { return strcmp(v1->string.s, v2->string.s) < 0; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue