diff options
author | Vincent Ambo <tazjin@google.com> | 2020-05-22T23·52+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2020-05-22T23·52+0100 |
commit | 6b447f4b259e929faf0add0cf0ad36309a7ec13d (patch) | |
tree | 23df784b690954c5277182832158800fed792668 /third_party/nix/src/libexpr | |
parent | 8c28be1b69a66f16fd1c711931b5a6f6948a8a2a (diff) |
chore(3p/nix/libexpr): Expose separate insert & "upsert" methods r/818
Reading more through the old code, it seems like the intention /sometimes/ is to replace values.
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r-- | third_party/nix/src/libexpr/attr-set.cc | 7 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/attr-set.hh | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/third_party/nix/src/libexpr/attr-set.cc b/third_party/nix/src/libexpr/attr-set.cc index 55b1d0ccd540..0e4cf5d9dc5f 100644 --- a/third_party/nix/src/libexpr/attr-set.cc +++ b/third_party/nix/src/libexpr/attr-set.cc @@ -21,7 +21,7 @@ namespace nix { // This behaviour is mimicked by using .insert(), which will *not* // override existing values. void Bindings::push_back(const Attr& attr) { - auto [_, inserted] = attributes_.insert_or_assign(attr.name, attr); + auto [_, inserted] = attributes_.insert({attr.name, attr}); if (!inserted) { DLOG(WARNING) << "attempted to insert duplicate attribute for key '" @@ -29,6 +29,11 @@ void Bindings::push_back(const Attr& attr) { } } +// Insert or assign (i.e. replace) a value in the attribute set. +void Bindings::insert_or_assign(const Attr& attr) { + attributes_.insert_or_assign(attr.name, attr); +} + size_t Bindings::size() { return attributes_.size(); } size_t Bindings::capacity() { return 0; } diff --git a/third_party/nix/src/libexpr/attr-set.hh b/third_party/nix/src/libexpr/attr-set.hh index 5837b5cbdc9c..6b68b4664a09 100644 --- a/third_party/nix/src/libexpr/attr-set.hh +++ b/third_party/nix/src/libexpr/attr-set.hh @@ -50,10 +50,12 @@ class Bindings { // Is this attribute set empty? bool empty(); - // TODO(tazjin): rename - // TODO(tazjin): does this need to copy? + // Insert, but do not replace, values in the attribute set. void push_back(const Attr& attr); + // Insert a value, or replace an existing one. + void insert_or_assign(const Attr& attr); + // Look up a specific element of the attribute set. iterator find(const Symbol& name); |