mirror of
https://github.com/NixOS/nix
synced 2025-07-07 01:51:47 +02:00
Optimize small lists
The value pointers of lists with 1 or 2 elements are now stored in the list value itself. In particular, this makes the "concatMap (x: if cond then [(f x)] else [])" idiom cheaper.
This commit is contained in:
parent
14be783676
commit
b83801f8b3
11 changed files with 157 additions and 121 deletions
|
@ -1127,13 +1127,13 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
|||
attrs2["type"] = "bool";
|
||||
attrs2["value"] = v->boolean ? "true" : "false";
|
||||
xml.writeEmptyElement("meta", attrs2);
|
||||
} else if (v->type == tList) {
|
||||
} else if (v->isList()) {
|
||||
attrs2["type"] = "strings";
|
||||
XMLOpenElement m(xml, "meta", attrs2);
|
||||
for (unsigned int j = 0; j < v->list.length; ++j) {
|
||||
if (v->list.elems[j]->type != tString) continue;
|
||||
for (unsigned int j = 0; j < v->listSize(); ++j) {
|
||||
if (v->listElems()[j]->type != tString) continue;
|
||||
XMLAttrs attrs3;
|
||||
attrs3["value"] = v->list.elems[j]->string.s;
|
||||
attrs3["value"] = v->listElems()[j]->string.s;
|
||||
xml.writeEmptyElement("string", attrs3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
Path drvPath = keepDerivations ? i.queryDrvPath() : "";
|
||||
|
||||
Value & v(*state.allocValue());
|
||||
manifest.list.elems[n++] = &v;
|
||||
manifest.listElems()[n++] = &v;
|
||||
state.mkAttrs(v, 16);
|
||||
|
||||
mkString(*state.allocAttr(v, state.sType), "derivation");
|
||||
|
@ -69,7 +69,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
|||
state.mkList(vOutputs, outputs.size());
|
||||
unsigned int m = 0;
|
||||
for (auto & j : outputs) {
|
||||
mkString(*(vOutputs.list.elems[m++] = state.allocValue()), j.first);
|
||||
mkString(*(vOutputs.listElems()[m++] = state.allocValue()), j.first);
|
||||
Value & vOutputs = *state.allocAttr(v, state.symbols.create(j.first));
|
||||
state.mkAttrs(vOutputs, 2);
|
||||
mkString(*state.allocAttr(vOutputs, state.sOutPath), j.second);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue