aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/parser.y
diff options
context:
space:
mode:
authorEt7f3 <cadeaudeelie@gmail.com>2023-02-11 00:37:23 +0100
committerEt7f3 <cadeaudeelie@gmail.com>2023-02-16 19:53:55 +0100
commitcec23f5ddab31fb7704aa7d822a508690e416ab6 (patch)
treee81d7163de714f295ffc322fa28ddbf635d119aa /src/libexpr/parser.y
parentfa89d317b7c7590a59db44bb369fcfe6baee4296 (diff)
ExprOpHasAttr,ExprSelect,stripIndentation,binds,formals: delete losts objects
We are looking for *$ because it indicate that it was constructed with a new but not release. De-referencing shallow copy so deleting as whole might create dangling pointer that's why we move it so we delete a empty containers + the nice perf boost.
Diffstat (limited to 'src/libexpr/parser.y')
-rw-r--r--src/libexpr/parser.y21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index 1dd4a801f..dec5818fc 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -90,7 +90,7 @@ static void dupAttr(const EvalState & state, Symbol attr, const PosIdx pos, cons
}
-static void addAttr(ExprAttrs * attrs, AttrPath & attrPath,
+static void addAttr(ExprAttrs * attrs, AttrPath && attrPath,
Expr * e, const PosIdx pos, const nix::EvalState & state)
{
AttrPath::iterator i;
@@ -188,7 +188,7 @@ static Formals * toFormals(ParseData & data, ParserFormals * formals,
static Expr * stripIndentation(const PosIdx pos, SymbolTable & symbols,
- std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> & es)
+ std::vector<std::pair<PosIdx, std::variant<Expr *, StringToken>>> && es)
{
if (es.empty()) return new ExprString("");
@@ -408,7 +408,7 @@ expr_op
| expr_op OR expr_op { $$ = new ExprOpOr(makeCurPos(@2, data), $1, $3); }
| expr_op IMPL expr_op { $$ = new ExprOpImpl(makeCurPos(@2, data), $1, $3); }
| expr_op UPDATE expr_op { $$ = new ExprOpUpdate(makeCurPos(@2, data), $1, $3); }
- | expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, *$3); }
+ | expr_op '?' attrpath { $$ = new ExprOpHasAttr($1, std::move(*$3)); delete $3; }
| expr_op '+' expr_op
{ $$ = new ExprConcatStrings(makeCurPos(@2, data), false, new std::vector<std::pair<PosIdx, Expr *> >({{makeCurPos(@1, data), $1}, {makeCurPos(@3, data), $3}})); }
| expr_op '-' expr_op { $$ = new ExprCall(makeCurPos(@2, data), new ExprVar(data->symbols.create("__sub")), {$1, $3}); }
@@ -431,9 +431,9 @@ expr_app
expr_select
: expr_simple '.' attrpath
- { $$ = new ExprSelect(CUR_POS, $1, *$3, 0); }
+ { $$ = new ExprSelect(CUR_POS, $1, std::move(*$3), nullptr); delete $3; }
| expr_simple '.' attrpath OR_KW expr_select
- { $$ = new ExprSelect(CUR_POS, $1, *$3, $5); }
+ { $$ = new ExprSelect(CUR_POS, $1, std::move(*$3), $5); delete $3; }
| /* Backwards compatibility: because Nixpkgs has a rarely used
function named ‘or’, allow stuff like ‘map or [...]’. */
expr_simple OR_KW
@@ -453,7 +453,8 @@ expr_simple
| FLOAT { $$ = new ExprFloat($1); }
| '"' string_parts '"' { $$ = $2; }
| IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {
- $$ = stripIndentation(CUR_POS, data->symbols, *$2);
+ $$ = stripIndentation(CUR_POS, data->symbols, std::move(*$2));
+ delete $2;
}
| path_start PATH_END
| path_start string_parts_interpolated PATH_END {
@@ -533,7 +534,7 @@ ind_string_parts
;
binds
- : binds attrpath '=' expr ';' { $$ = $1; addAttr($$, *$2, $4, makeCurPos(@2, data), data->state); }
+ : binds attrpath '=' expr ';' { $$ = $1; addAttr($$, std::move(*$2), $4, makeCurPos(@2, data), data->state); delete $2; }
| binds INHERIT attrs ';'
{ $$ = $1;
for (auto & i : *$3) {
@@ -542,6 +543,7 @@ binds
auto pos = makeCurPos(@3, data);
$$->attrs.emplace(i.symbol, ExprAttrs::AttrDef(new ExprVar(CUR_POS, i.symbol), pos, true));
}
+ delete $3;
}
| binds INHERIT '(' expr ')' attrs ';'
{ $$ = $1;
@@ -551,6 +553,7 @@ binds
dupAttr(data->state, i.symbol, makeCurPos(@6, data), $$->attrs[i.symbol].pos);
$$->attrs.emplace(i.symbol, ExprAttrs::AttrDef(new ExprSelect(CUR_POS, $4, i.symbol), makeCurPos(@6, data)));
}
+ delete $6;
}
| { $$ = new ExprAttrs(makeCurPos(@0, data)); }
;
@@ -612,9 +615,9 @@ expr_list
formals
: formal ',' formals
- { $$ = $3; $$->formals.push_back(*$1); }
+ { $$ = $3; $$->formals.emplace_back(*$1); delete $1; }
| formal
- { $$ = new ParserFormals; $$->formals.push_back(*$1); $$->ellipsis = false; }
+ { $$ = new ParserFormals; $$->formals.emplace_back(*$1); $$->ellipsis = false; delete $1; }
|
{ $$ = new ParserFormals; $$->ellipsis = false; }
| ELLIPSIS