chore(3p/nix/libexpr): Expose separate insert & "upsert" methods

Reading more through the old code, it seems like the intention
/sometimes/ is to replace values.
This commit is contained in:
Vincent Ambo 2020-05-23 00:52:20 +01:00
parent 8c28be1b69
commit 6b447f4b25
2 changed files with 10 additions and 3 deletions

View file

@ -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; }