about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr/attr-set.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/attr-set.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/attr-set.cc')
-rw-r--r--third_party/nix/src/libexpr/attr-set.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/third_party/nix/src/libexpr/attr-set.cc b/third_party/nix/src/libexpr/attr-set.cc
index 8b2af8639eff..e0fac9234b14 100644
--- a/third_party/nix/src/libexpr/attr-set.cc
+++ b/third_party/nix/src/libexpr/attr-set.cc
@@ -37,6 +37,14 @@ Bindings::iterator Bindings::find(const Symbol& name) {
 Bindings::iterator Bindings::begin() { return &(attributes_.begin()->second); }
 
 Bindings::iterator Bindings::end() { return &(attributes_.end()->second); }
+void Bindings::merge(Bindings* other) {
+  // We want the values from the other attribute set to take
+  // precedence, but .merge() works the other way around.
+  //
+  // To work around that, we merge and then swap.
+  other->attributes_.merge(attributes_);
+  attributes_.swap(other->attributes_);
+}
 
 // /* Allocate a new array of attributes for an attribute set with a specific
 //    capacity. The space is implicitly reserved after the Bindings structure.