refactor(3p/nix/libexpr): Use range insertion to merge nix::Bindings

Instead of manually iterating over the two bindings to be combined,
this adds a new static method on the Bindings class which merges two
attribute sets by calling the range insertion operator over them.

In some anecdotal tests, this can lead to a ~10% speed bump -
depending on the specific operation.

Change-Id: I5dea03b0589a83a789d3a8a0fc81d0d9e6598371
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1216
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
Vincent Ambo 2020-07-16 19:31:30 +01:00 committed by tazjin
parent 1ba5aa293b
commit cb3d967508
3 changed files with 25 additions and 18 deletions

View file

@ -19,6 +19,7 @@
#include "libexpr/eval-inline.hh"
#include "libexpr/function-trace.hh"
#include "libexpr/value.hh"
#include "libstore/derivations.hh"
#include "libstore/download.hh"
#include "libstore/globals.hh"
@ -1240,11 +1241,9 @@ void ExprOpUpdate::eval(EvalState& state, Env& env, Value& dest) {
state.nrOpUpdates++;
state.mkAttrs(dest, v1.attrs->size() + v2.attrs->size());
// Merge the sets, preferring values from the second set.
dest.attrs->merge(*v1.attrs);
dest.attrs->merge(*v2.attrs);
clearValue(dest);
dest.type = tAttrs;
dest.attrs = Bindings::Merge(*v1.attrs, *v2.attrs);
}
void ExprOpConcatLists::eval(EvalState& state, Env& env, Value& v) {