Skip to content

Commit 631fb6c

Browse files
libexpr: move ExprConcatStrings data to Exprs::alloc
ExprConcatStrings no longer consumes the vector argument Co-authored-by: John Ericson <[email protected]>
1 parent 2d83bc6 commit 631fb6c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/libexpr/include/nix/expr/nixexpr.hh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,19 @@ struct ExprConcatStrings : Expr
760760
{
761761
PosIdx pos;
762762
bool forceString;
763-
std::vector<std::pair<PosIdx, Expr *>> es;
764-
ExprConcatStrings(const PosIdx & pos, bool forceString, std::vector<std::pair<PosIdx, Expr *>> && es)
763+
std::span<std::pair<PosIdx, Expr *>> es;
764+
765+
ExprConcatStrings(
766+
std::pmr::polymorphic_allocator<char> & alloc,
767+
const PosIdx & pos,
768+
bool forceString,
769+
const std::vector<std::pair<PosIdx, Expr *>> & es)
765770
: pos(pos)
766771
, forceString(forceString)
767-
, es(std::move(es)) {};
772+
, es({alloc.allocate_object<std::pair<PosIdx, Expr *>>(es.size()), es.size()})
773+
{
774+
std::ranges::copy(es, this->es.begin());
775+
};
768776

769777
PosIdx getPos() const override
770778
{

src/libexpr/include/nix/expr/parser-state.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ ParserState::stripIndentation(const PosIdx pos, std::vector<std::pair<PosIdx, st
341341
auto * const result = (es2)[0].second;
342342
return result;
343343
}
344-
return new ExprConcatStrings(pos, true, std::move(es2));
344+
return new ExprConcatStrings(alloc, pos, true, std::move(es2));
345345
}
346346

347347
inline PosIdx LexerState::at(const ParserLocation & loc)

src/libexpr/parser.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ expr_op
253253
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(state->at(@2), $1, $3); }
254254
| expr_op '?' attrpath { $$ = new ExprOpHasAttr(state->alloc, $1, std::move($3)); }
255255
| expr_op '+' expr_op
256-
{ $$ = new ExprConcatStrings(state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
256+
{ $$ = new ExprConcatStrings(state->alloc, state->at(@2), false, {{state->at(@1), $1}, {state->at(@3), $3}}); }
257257
| expr_op '-' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.sub), {$1, $3}); }
258258
| expr_op '*' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.mul), {$1, $3}); }
259259
| expr_op '/' expr_op { $$ = new ExprCall(state->at(@2), new ExprVar(state->s.div), {$1, $3}); }
@@ -309,7 +309,7 @@ expr_simple
309309
| path_start PATH_END
310310
| path_start string_parts_interpolated PATH_END {
311311
$2.insert($2.begin(), {state->at(@1), $1});
312-
$$ = new ExprConcatStrings(CUR_POS, false, std::move($2));
312+
$$ = new ExprConcatStrings(state->alloc, CUR_POS, false, std::move($2));
313313
}
314314
| SPATH {
315315
std::string_view path($1.p + 1, $1.l - 2);
@@ -343,7 +343,7 @@ expr_simple
343343

344344
string_parts
345345
: STR { $$ = $1; }
346-
| string_parts_interpolated { $$ = new ExprConcatStrings(CUR_POS, true, std::move($1)); }
346+
| string_parts_interpolated { $$ = new ExprConcatStrings(state->alloc, CUR_POS, true, std::move($1)); }
347347
| { $$ = std::string_view(); }
348348
;
349349

0 commit comments

Comments
 (0)