mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
libexpr: allocate ExprPath strings in the allocator
This commit is contained in:
parent
13a236ba29
commit
f70b0b599c
3 changed files with 10 additions and 8 deletions
|
|
@ -212,14 +212,16 @@ struct ExprString : Expr
|
||||||
struct ExprPath : Expr
|
struct ExprPath : Expr
|
||||||
{
|
{
|
||||||
ref<SourceAccessor> accessor;
|
ref<SourceAccessor> accessor;
|
||||||
std::string s;
|
|
||||||
Value v;
|
Value v;
|
||||||
|
|
||||||
ExprPath(ref<SourceAccessor> accessor, std::string s)
|
ExprPath(std::pmr::polymorphic_allocator<char> & alloc, ref<SourceAccessor> accessor, std::string_view sv)
|
||||||
: accessor(accessor)
|
: accessor(accessor)
|
||||||
, s(std::move(s))
|
|
||||||
{
|
{
|
||||||
v.mkPath(&*accessor, this->s.c_str());
|
auto len = sv.length();
|
||||||
|
char * s = alloc.allocate(len + 1);
|
||||||
|
sv.copy(s, len);
|
||||||
|
s[len] = '\0';
|
||||||
|
v.mkPath(&*accessor, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Value * maybeThunk(EvalState & state, Env & env) override;
|
Value * maybeThunk(EvalState & state, Env & env) override;
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ void ExprString::show(const SymbolTable & symbols, std::ostream & str) const
|
||||||
|
|
||||||
void ExprPath::show(const SymbolTable & symbols, std::ostream & str) const
|
void ExprPath::show(const SymbolTable & symbols, std::ostream & str) const
|
||||||
{
|
{
|
||||||
str << s;
|
str << v.pathStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprVar::show(const SymbolTable & symbols, std::ostream & str) const
|
void ExprVar::show(const SymbolTable & symbols, std::ostream & str) const
|
||||||
|
|
|
||||||
|
|
@ -392,8 +392,8 @@ path_start
|
||||||
root filesystem accessor, rather than the accessor of the
|
root filesystem accessor, rather than the accessor of the
|
||||||
current Nix expression. */
|
current Nix expression. */
|
||||||
literal.front() == '/'
|
literal.front() == '/'
|
||||||
? new ExprPath(state->rootFS, std::move(path))
|
? new ExprPath(state->alloc, state->rootFS, path)
|
||||||
: new ExprPath(state->basePath.accessor, std::move(path));
|
: new ExprPath(state->alloc, state->basePath.accessor, path);
|
||||||
}
|
}
|
||||||
| HPATH {
|
| HPATH {
|
||||||
if (state->settings.pureEval) {
|
if (state->settings.pureEval) {
|
||||||
|
|
@ -403,7 +403,7 @@ path_start
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Path path(getHome() + std::string($1.p + 1, $1.l - 1));
|
Path path(getHome() + std::string($1.p + 1, $1.l - 1));
|
||||||
$$ = new ExprPath(ref<SourceAccessor>(state->rootFS), std::move(path));
|
$$ = new ExprPath(state->alloc, ref<SourceAccessor>(state->rootFS), path);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue