about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-22T00·52+0100
committerVincent Ambo <tazjin@google.com>2020-05-22T00·52+0100
commitee4637e3a22a1efc480bb66ea025afd107d1b158 (patch)
tree1cf734ff3f038adf66505698ade086ef1142e6e6 /third_party/nix/src/libexpr/eval.cc
parent28e347effe1ba4325fc485e920bda45c838e0450 (diff)
refactor(3p/nix/libexpr): Use absl::btree_map::merge for '//' r/800
Instead of doing some sort of inline merge-sort of the two attribute
sets, use the attribute sets merge function.

This commit alone does not build and is not supposed to.
Diffstat (limited to 'third_party/nix/src/libexpr/eval.cc')
-rw-r--r--third_party/nix/src/libexpr/eval.cc25
1 files changed, 3 insertions, 22 deletions
diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc
index 760bada7b0bf..dcaaadbd0896 100644
--- a/third_party/nix/src/libexpr/eval.cc
+++ b/third_party/nix/src/libexpr/eval.cc
@@ -1301,31 +1301,12 @@ void ExprOpUpdate::eval(EvalState& state, Env& env, Value& v) {
     return;
   }
 
-  state.mkAttrs(v, v1.attrs->size() + v2.attrs->size());
+  state.mkAttrs(v, /* capacity = */ 0);
 
   /* Merge the sets, preferring values from the second set.  Make
      sure to keep the resulting vector in sorted order. */
-  Bindings::iterator i = v1.attrs->begin();
-  Bindings::iterator j = v2.attrs->begin();
-
-  while (i != v1.attrs->end() && j != v2.attrs->end()) {
-    if (i->name == j->name) {
-      v.attrs->push_back(*j);
-      ++i;
-      ++j;
-    } else if (i->name < j->name) {
-      v.attrs->push_back(*i++);
-    } else {
-      v.attrs->push_back(*j++);
-    }
-  }
-
-  while (i != v1.attrs->end()) {
-    v.attrs->push_back(*i++);
-  }
-  while (j != v2.attrs->end()) {
-    v.attrs->push_back(*j++);
-  }
+  v.attrs->merge(v1.attrs);
+  v.attrs->merge(v2.attrs);
 
   state.nrOpUpdateValuesCopied += v.attrs->size();
 }