mirror of
https://github.com/NixOS/nix.git
synced 2025-11-27 12:41:00 +01:00
libexpr: factor out functions for moving data to a new allocator
This commit is contained in:
parent
5d066386b5
commit
43a183120a
2 changed files with 20 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));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue