mirror of
https://github.com/NixOS/nix.git
synced 2025-11-28 13:11:00 +01:00
Merge pull request #14635 from Radvendii/alloc-exprlet-exprattrs
libexpr: move the ExprLet::attrs allocations into the arena
This commit is contained in:
commit
3bac0d7aa2
2 changed files with 21 additions and 16 deletions
|
|
@ -438,6 +438,7 @@ struct ExprAttrs : Expr
|
||||||
std::shared_ptr<const StaticEnv> bindInheritSources(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
|
std::shared_ptr<const StaticEnv> bindInheritSources(EvalState & es, const std::shared_ptr<const StaticEnv> & env);
|
||||||
Env * buildInheritFromEnv(EvalState & state, Env & up);
|
Env * buildInheritFromEnv(EvalState & state, Env & up);
|
||||||
void showBindings(const SymbolTable & symbols, std::ostream & str) const;
|
void showBindings(const SymbolTable & symbols, std::ostream & str) const;
|
||||||
|
void moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExprList : Expr
|
struct ExprList : Expr
|
||||||
|
|
@ -622,6 +623,7 @@ struct ExprCall : Expr
|
||||||
|
|
||||||
virtual void resetCursedOr() override;
|
virtual void resetCursedOr() override;
|
||||||
virtual void warnIfCursedOr(const SymbolTable & symbols, const PosTable & positions) override;
|
virtual void warnIfCursedOr(const SymbolTable & symbols, const PosTable & positions) override;
|
||||||
|
void moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc);
|
||||||
COMMON_METHODS
|
COMMON_METHODS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -399,18 +399,19 @@ ExprAttrs::bindInheritSources(EvalState & es, const std::shared_ptr<const Static
|
||||||
return inner;
|
return inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExprAttrs::moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc)
|
||||||
|
{
|
||||||
|
AttrDefs newAttrs{std::move(*attrs), alloc};
|
||||||
|
attrs.emplace(std::move(newAttrs), alloc);
|
||||||
|
DynamicAttrDefs newDynamicAttrs{std::move(*dynamicAttrs), alloc};
|
||||||
|
dynamicAttrs.emplace(std::move(newDynamicAttrs), alloc);
|
||||||
|
if (inheritFromExprs)
|
||||||
|
inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>(std::move(*inheritFromExprs), alloc);
|
||||||
|
}
|
||||||
|
|
||||||
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
// Move storage into the Exprs arena
|
moveDataToAllocator(es.mem.exprs.alloc);
|
||||||
{
|
|
||||||
auto arena = es.mem.exprs.alloc;
|
|
||||||
AttrDefs newAttrs{std::move(*attrs), arena};
|
|
||||||
attrs.emplace(std::move(newAttrs), arena);
|
|
||||||
DynamicAttrDefs newDynamicAttrs{std::move(*dynamicAttrs), arena};
|
|
||||||
dynamicAttrs.emplace(std::move(newDynamicAttrs), arena);
|
|
||||||
if (inheritFromExprs)
|
|
||||||
inheritFromExprs = std::make_unique<std::pmr::vector<Expr *>>(std::move(*inheritFromExprs), arena);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (es.debugRepl)
|
if (es.debugRepl)
|
||||||
es.exprEnvs.insert(std::make_pair(this, env));
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
@ -484,14 +485,15 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
|
||||||
body->bindVars(es, newEnv);
|
body->bindVars(es, newEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExprCall::moveDataToAllocator(std::pmr::polymorphic_allocator<char> & alloc)
|
||||||
|
{
|
||||||
|
std::pmr::vector<Expr *> newArgs{std::move(*args), alloc};
|
||||||
|
args.emplace(std::move(newArgs), alloc);
|
||||||
|
}
|
||||||
|
|
||||||
void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
// Move storage into the Exprs arena
|
moveDataToAllocator(es.mem.exprs.alloc);
|
||||||
{
|
|
||||||
auto arena = es.mem.exprs.alloc;
|
|
||||||
std::pmr::vector<Expr *> newArgs{std::move(*args), arena};
|
|
||||||
args.emplace(std::move(newArgs), arena);
|
|
||||||
}
|
|
||||||
if (es.debugRepl)
|
if (es.debugRepl)
|
||||||
es.exprEnvs.insert(std::make_pair(this, env));
|
es.exprEnvs.insert(std::make_pair(this, env));
|
||||||
|
|
||||||
|
|
@ -502,6 +504,7 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &
|
||||||
|
|
||||||
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> & env)
|
||||||
{
|
{
|
||||||
|
attrs->moveDataToAllocator(es.mem.exprs.alloc);
|
||||||
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
|
auto newEnv = [&]() -> std::shared_ptr<const StaticEnv> {
|
||||||
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs->attrs->size());
|
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, attrs->attrs->size());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue