about summary refs log tree commit diff
path: root/third_party/nix/src/libexpr
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-23T19·29+0100
committerVincent Ambo <tazjin@google.com>2020-05-23T19·29+0100
commit55b1a4764752e8a52df326b7e6ec9809c28c3a8e (patch)
treee26b9ca9686b5211da95e4320a3eb1aef78fbae2 /third_party/nix/src/libexpr
parentab1fbd4c6ec65966a28abbccc1efefe74d189bba (diff)
refactor(3p/nix/libexpr): Make other 'const' in Bindings::merge r/828
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r--third_party/nix/src/libexpr/attr-set.cc11
-rw-r--r--third_party/nix/src/libexpr/attr-set.hh2
2 files changed, 5 insertions, 8 deletions
diff --git a/third_party/nix/src/libexpr/attr-set.cc b/third_party/nix/src/libexpr/attr-set.cc
index 495f9816c7aa..6310cc66b726 100644
--- a/third_party/nix/src/libexpr/attr-set.cc
+++ b/third_party/nix/src/libexpr/attr-set.cc
@@ -59,13 +59,10 @@ Bindings::iterator Bindings::begin() { return attributes_.begin(); }
 
 Bindings::iterator Bindings::end() { return attributes_.end(); }
 
-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_);
+void Bindings::merge(const Bindings& other) {
+  for (auto& [key, value] : other.attributes_) {
+    this->attributes_[key] = value;
+  }
 }
 
 Bindings* Bindings::NewGC() { return new (GC) Bindings; }
diff --git a/third_party/nix/src/libexpr/attr-set.hh b/third_party/nix/src/libexpr/attr-set.hh
index 19d1c8f530e4..37e6d5e1ca8f 100644
--- a/third_party/nix/src/libexpr/attr-set.hh
+++ b/third_party/nix/src/libexpr/attr-set.hh
@@ -64,7 +64,7 @@ class Bindings {
   iterator end();
 
   // Merge values from other into the current attribute
-  void merge(Bindings* other);
+  void merge(const Bindings& other);
 
   // ???
   [[deprecated]] size_t capacity();