mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
parser.y: use std::move() to avoid unnecessary copies
With #14314, in some places in the parser we started using C++ objects directly rather than pointers. In those places lines like `$$ = $1` now imply a copy when we don't need one. This commit changes those to `$$ = std::move($1)` to avoid those copies.
This commit is contained in:
parent
126f30deb2
commit
ef8dd58d9b
1 changed files with 11 additions and 11 deletions
|
|
@ -345,8 +345,8 @@ string_parts
|
|||
|
||||
string_parts_interpolated
|
||||
: string_parts_interpolated STR
|
||||
{ $$ = $1; $$.emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
|
||||
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $$.emplace_back(state->at(@2), $3); }
|
||||
{ $$ = std::move($1); $$.emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
|
||||
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
|
||||
| DOLLAR_CURLY expr '}' { $$.emplace_back(state->at(@1), $2); }
|
||||
| STR DOLLAR_CURLY expr '}' {
|
||||
$$.emplace_back(state->at(@1), new ExprString(state->alloc, $1));
|
||||
|
|
@ -391,8 +391,8 @@ path_start
|
|||
;
|
||||
|
||||
ind_string_parts
|
||||
: ind_string_parts IND_STR { $$ = $1; $$.emplace_back(state->at(@2), $2); }
|
||||
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $$.emplace_back(state->at(@2), $3); }
|
||||
: ind_string_parts IND_STR { $$ = std::move($1); $$.emplace_back(state->at(@2), $2); }
|
||||
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
|
||||
| { }
|
||||
;
|
||||
|
||||
|
|
@ -440,9 +440,9 @@ binds1
|
|||
;
|
||||
|
||||
attrs
|
||||
: attrs attr { $$ = $1; $$.emplace_back(AttrName(state->symbols.create($2)), state->at(@2)); }
|
||||
: attrs attr { $$ = std::move($1); $$.emplace_back(AttrName(state->symbols.create($2)), state->at(@2)); }
|
||||
| attrs string_attr
|
||||
{ $$ = $1;
|
||||
{ $$ = std::move($1);
|
||||
std::visit(overloaded {
|
||||
[&](std::string_view str) { $$.emplace_back(AttrName(state->symbols.create(str)), state->at(@2)); },
|
||||
[&](Expr * expr) {
|
||||
|
|
@ -457,20 +457,20 @@ attrs
|
|||
;
|
||||
|
||||
attrpath
|
||||
: attrpath '.' attr { $$ = $1; $$.push_back(AttrName(state->symbols.create($3))); }
|
||||
: attrpath '.' attr { $$ = std::move($1); $$.push_back(AttrName(state->symbols.create($3))); }
|
||||
| attrpath '.' string_attr
|
||||
{ $$ = $1;
|
||||
{ $$ = std::move($1);
|
||||
std::visit(overloaded {
|
||||
[&](std::string_view str) { $$.push_back(AttrName(state->symbols.create(str))); },
|
||||
[&](Expr * expr) { $$.push_back(AttrName(expr)); }
|
||||
}, $3);
|
||||
}, std::move($3));
|
||||
}
|
||||
| attr { $$.push_back(AttrName(state->symbols.create($1))); }
|
||||
| string_attr
|
||||
{ std::visit(overloaded {
|
||||
[&](std::string_view str) { $$.push_back(AttrName(state->symbols.create(str))); },
|
||||
[&](Expr * expr) { $$.push_back(AttrName(expr)); }
|
||||
}, $1);
|
||||
}, std::move($1));
|
||||
}
|
||||
;
|
||||
|
||||
|
|
@ -480,7 +480,7 @@ attr
|
|||
;
|
||||
|
||||
string_attr
|
||||
: '"' string_parts '"' { $$ = $2; }
|
||||
: '"' string_parts '"' { $$ = std::move($2); }
|
||||
| DOLLAR_CURLY expr '}' { $$ = $2; }
|
||||
;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue