aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/attr-set.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-01-04 19:23:11 +0100
committerEelco Dolstra <edolstra@gmail.com>2022-01-04 19:23:11 +0100
commit17daec0b832205df781f6443292667c9aa617047 (patch)
tree43f60d7ce1a0e24edb7897e26dd60ef14c93fa46 /src/libexpr/attr-set.cc
parentca5baf239277daecef489a415fe157094bd7e799 (diff)
Move empty attrset optimisation
Diffstat (limited to 'src/libexpr/attr-set.cc')
-rw-r--r--src/libexpr/attr-set.cc8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/libexpr/attr-set.cc b/src/libexpr/attr-set.cc
index d74243f45..fc971957d 100644
--- a/src/libexpr/attr-set.cc
+++ b/src/libexpr/attr-set.cc
@@ -12,6 +12,8 @@ namespace nix {
structure. */
Bindings * EvalState::allocBindings(size_t capacity)
{
+ if (capacity == 0)
+ return &emptyBindings;
if (capacity > std::numeric_limits<Bindings::size_t>::max())
throw Error("attribute set of size %d is too big", capacity);
return new (allocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings((Bindings::size_t) capacity);
@@ -20,10 +22,6 @@ Bindings * EvalState::allocBindings(size_t capacity)
void EvalState::mkAttrs(Value & v, size_t capacity)
{
- if (capacity == 0) {
- v = vEmptySet;
- return;
- }
v.mkAttrs(allocBindings(capacity));
nrAttrsets++;
nrAttrsInAttrsets += capacity;
@@ -63,7 +61,7 @@ Value & BindingsBuilder::alloc(std::string_view name, ptr<Pos> pos)
void Bindings::sort()
{
- std::sort(begin(), end());
+ if (size_) std::sort(begin(), end());
}