about summary refs log tree commit diff
path: root/src/libexpr/attr-set.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-23T21·11+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-23T21·11+0200
commitc8bb2371ebf25ab78abde84e3c5742f9844a74b7 (patch)
tree53aeea8ded7f7b21636a87414f715f897962ffcd /src/libexpr/attr-set.cc
parent16c9935fa9487f504b1e9c7f14d0f85ac870a62c (diff)
Optimize empty sets
This reduces the number of Bindings allocations by about 10%.
Diffstat (limited to 'src/libexpr/attr-set.cc')
-rw-r--r--src/libexpr/attr-set.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libexpr/attr-set.cc b/src/libexpr/attr-set.cc
index 9ac5e603199a..910428c02686 100644
--- a/src/libexpr/attr-set.cc
+++ b/src/libexpr/attr-set.cc
@@ -29,13 +29,17 @@ Bindings * EvalState::allocBindings(Bindings::size_t capacity)
 }
 
 
-void EvalState::mkAttrs(Value & v, unsigned int expected)
+void EvalState::mkAttrs(Value & v, unsigned int capacity)
 {
+    if (capacity == 0) {
+        v = vEmptySet;
+        return;
+    }
     clearValue(v);
     v.type = tAttrs;
-    v.attrs = allocBindings(expected);
+    v.attrs = allocBindings(capacity);
     nrAttrsets++;
-    nrAttrsInAttrsets += expected;
+    nrAttrsInAttrsets += capacity;
 }