diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-01-04 17:39:16 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-01-04 18:00:33 +0100 |
commit | 6d9a6d2cc3a20c9047436d174c9f91a2223da220 (patch) | |
tree | 2bf36cb443a80f56db38e10c8afe2c749ff3bdcc /src/libexpr/attr-set.cc | |
parent | 1ffacad8a5201713659d5e18db47b2020bdc6aa1 (diff) |
Ensure that attrsets are sorted
Previously you had to remember to call value->attrs->sort() after
populating value->attrs. Now there is a BindingsBuilder helper that
wraps Bindings and ensures that sort() is called before you can use
it.
Diffstat (limited to 'src/libexpr/attr-set.cc')
-rw-r--r-- | src/libexpr/attr-set.cc | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/libexpr/attr-set.cc b/src/libexpr/attr-set.cc index b6091c955..d74243f45 100644 --- a/src/libexpr/attr-set.cc +++ b/src/libexpr/attr-set.cc @@ -41,16 +41,39 @@ Value * EvalState::allocAttr(Value & vAttrs, const Symbol & name) } -Value * EvalState::allocAttr(Value & vAttrs, const std::string & name) +Value * EvalState::allocAttr(Value & vAttrs, std::string_view name) { return allocAttr(vAttrs, symbols.create(name)); } +Value & BindingsBuilder::alloc(const Symbol & name, ptr<Pos> pos) +{ + auto value = state.allocValue(); + bindings->push_back(Attr(name, value, pos)); + return *value; +} + + +Value & BindingsBuilder::alloc(std::string_view name, ptr<Pos> pos) +{ + return alloc(state.symbols.create(name), pos); +} + + void Bindings::sort() { std::sort(begin(), end()); } +Value & Value::mkAttrs(BindingsBuilder & bindings) +{ + clearValue(); + internalType = tAttrs; + attrs = bindings.finish(); + return *this; +} + + } |