forked from lix-project/lix
Move empty attrset optimisation
This commit is contained in:
parent
ca5baf2392
commit
17daec0b83
|
@ -12,6 +12,8 @@ namespace nix {
|
||||||
structure. */
|
structure. */
|
||||||
Bindings * EvalState::allocBindings(size_t capacity)
|
Bindings * EvalState::allocBindings(size_t capacity)
|
||||||
{
|
{
|
||||||
|
if (capacity == 0)
|
||||||
|
return &emptyBindings;
|
||||||
if (capacity > std::numeric_limits<Bindings::size_t>::max())
|
if (capacity > std::numeric_limits<Bindings::size_t>::max())
|
||||||
throw Error("attribute set of size %d is too big", capacity);
|
throw Error("attribute set of size %d is too big", capacity);
|
||||||
return new (allocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings((Bindings::size_t) 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)
|
void EvalState::mkAttrs(Value & v, size_t capacity)
|
||||||
{
|
{
|
||||||
if (capacity == 0) {
|
|
||||||
v = vEmptySet;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
v.mkAttrs(allocBindings(capacity));
|
v.mkAttrs(allocBindings(capacity));
|
||||||
nrAttrsets++;
|
nrAttrsets++;
|
||||||
nrAttrsInAttrsets += capacity;
|
nrAttrsInAttrsets += capacity;
|
||||||
|
@ -63,7 +61,7 @@ Value & BindingsBuilder::alloc(std::string_view name, ptr<Pos> pos)
|
||||||
|
|
||||||
void Bindings::sort()
|
void Bindings::sort()
|
||||||
{
|
{
|
||||||
std::sort(begin(), end());
|
if (size_) std::sort(begin(), end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -413,6 +413,7 @@ EvalState::EvalState(
|
||||||
, sSelf(symbols.create("self"))
|
, sSelf(symbols.create("self"))
|
||||||
, sEpsilon(symbols.create(""))
|
, sEpsilon(symbols.create(""))
|
||||||
, repair(NoRepair)
|
, repair(NoRepair)
|
||||||
|
, emptyBindings(0)
|
||||||
, store(store)
|
, store(store)
|
||||||
, buildStore(buildStore ? buildStore : store)
|
, buildStore(buildStore ? buildStore : store)
|
||||||
, regexCache(makeRegexCache())
|
, regexCache(makeRegexCache())
|
||||||
|
@ -454,8 +455,6 @@ EvalState::EvalState(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vEmptySet.mkAttrs(allocBindings(0));
|
|
||||||
|
|
||||||
createBaseEnv();
|
createBaseEnv();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
mode. */
|
mode. */
|
||||||
std::optional<PathSet> allowedPaths;
|
std::optional<PathSet> allowedPaths;
|
||||||
|
|
||||||
Value vEmptySet;
|
Bindings emptyBindings;
|
||||||
|
|
||||||
/* Store used to materialise .drv files. */
|
/* Store used to materialise .drv files. */
|
||||||
const ref<Store> store;
|
const ref<Store> store;
|
||||||
|
|
Loading…
Reference in a new issue