From b83801f8b3b48f4d69414401c8a51724946a8666 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 23 Jul 2015 22:05:09 +0200 Subject: 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. --- src/nix-env/nix-env.cc | 8 ++++---- src/nix-env/user-env.cc | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nix-env') diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 04f1016167a9..97a2bbdb7de0 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -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); } } diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index 35b1628e3c5c..9a20b94334f2 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -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); -- cgit 1.4.1