From cdc1a0bb6ec52cd05c1a72c00c3c3a4f716a429a Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 18 Jul 2020 16:40:15 +0100 Subject: refactor(3p/nix/libexpr): Back Nix lists with std::vector This change does away with the previous special-casing of lists of certain element sizes, and the use of raw C-style arrays. Lists are now backed by a std::vector of nix::Value*, which uses the traceable GC allocator. This change is unfortunately quite noisy because the accessor methods were updated/removed accordingly, so all callsites of Nix-related lists have changed. For some operations in primops.cc where keeping the previous code structure would have been more difficult with a "proper" vector, the implementation has been replaced with std::vector methods. For example, list concatenation now uses appropriate range inserts. Anecdotally the performance of this is about equal, to even slightly better, than the previous implementation. All language tests pass and the depot paths I've used for testing still evaluate. Change-Id: Ib5eca6c0207429cb323a330c838c3a2200b2c693 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1266 Tested-by: BuildkiteCI Reviewed-by: isomer Reviewed-by: Kane York Reviewed-by: glittershark --- third_party/nix/src/nix-env/user-env.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'third_party/nix/src/nix-env/user-env.cc') diff --git a/third_party/nix/src/nix-env/user-env.cc b/third_party/nix/src/nix-env/user-env.cc index 8130eafbdf..06329e74f3 100644 --- a/third_party/nix/src/nix-env/user-env.cc +++ b/third_party/nix/src/nix-env/user-env.cc @@ -51,29 +51,29 @@ bool createUserEnv(EvalState& state, DrvInfos& elems, const Path& profile, as the meta attributes. */ Path drvPath = keepDerivations ? i.queryDrvPath() : ""; - Value& v(*state.allocValue()); - manifest.listElems()[n++] = &v; - state.mkAttrs(v, 16); + Value* v = state.allocValue(); + (*manifest.list)[n++] = v; + state.mkAttrs(*v, 16); - mkString(*state.allocAttr(v, state.sType), "derivation"); - mkString(*state.allocAttr(v, state.sName), i.queryName()); + mkString(*state.allocAttr(*v, state.sType), "derivation"); + mkString(*state.allocAttr(*v, state.sName), i.queryName()); auto system = i.querySystem(); if (!system.empty()) { - mkString(*state.allocAttr(v, state.sSystem), system); + mkString(*state.allocAttr(*v, state.sSystem), system); } - mkString(*state.allocAttr(v, state.sOutPath), i.queryOutPath()); + mkString(*state.allocAttr(*v, state.sOutPath), i.queryOutPath()); if (!drvPath.empty()) { - mkString(*state.allocAttr(v, state.sDrvPath), i.queryDrvPath()); + mkString(*state.allocAttr(*v, state.sDrvPath), i.queryDrvPath()); } // Copy each output meant for installation. DrvInfo::Outputs outputs = i.queryOutputs(true); - Value& vOutputs = *state.allocAttr(v, state.sOutputs); + Value& vOutputs = *state.allocAttr(*v, state.sOutputs); state.mkList(vOutputs, outputs.size()); unsigned int m = 0; for (auto& j : outputs) { - mkString(*(vOutputs.listElems()[m++] = state.allocValue()), j.first); - Value& vOutputs = *state.allocAttr(v, state.symbols.Create(j.first)); + mkString(*((*vOutputs.list)[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); @@ -86,7 +86,7 @@ bool createUserEnv(EvalState& state, DrvInfos& elems, const Path& profile, } // Copy the meta attributes. - Value& vMeta = *state.allocAttr(v, state.sMeta); + Value& vMeta = *state.allocAttr(*v, state.sMeta); state.mkAttrs(vMeta, 16); StringSet metaNames = i.queryMetaNames(); for (auto& j : metaNames) { -- cgit 1.4.1