Skip to content

Commit ef8dd58

Browse files
committed
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.
1 parent 126f30d commit ef8dd58

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/libexpr/parser.y

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ string_parts
345345

346346
string_parts_interpolated
347347
: string_parts_interpolated STR
348-
{ $$ = $1; $$.emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
349-
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = $1; $$.emplace_back(state->at(@2), $3); }
348+
{ $$ = std::move($1); $$.emplace_back(state->at(@2), new ExprString(state->alloc, $2)); }
349+
| string_parts_interpolated DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
350350
| DOLLAR_CURLY expr '}' { $$.emplace_back(state->at(@1), $2); }
351351
| STR DOLLAR_CURLY expr '}' {
352352
$$.emplace_back(state->at(@1), new ExprString(state->alloc, $1));
@@ -391,8 +391,8 @@ path_start
391391
;
392392

393393
ind_string_parts
394-
: ind_string_parts IND_STR { $$ = $1; $$.emplace_back(state->at(@2), $2); }
395-
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = $1; $$.emplace_back(state->at(@2), $3); }
394+
: ind_string_parts IND_STR { $$ = std::move($1); $$.emplace_back(state->at(@2), $2); }
395+
| ind_string_parts DOLLAR_CURLY expr '}' { $$ = std::move($1); $$.emplace_back(state->at(@2), $3); }
396396
| { }
397397
;
398398

@@ -440,9 +440,9 @@ binds1
440440
;
441441

442442
attrs
443-
: attrs attr { $$ = $1; $$.emplace_back(AttrName(state->symbols.create($2)), state->at(@2)); }
443+
: attrs attr { $$ = std::move($1); $$.emplace_back(AttrName(state->symbols.create($2)), state->at(@2)); }
444444
| attrs string_attr
445-
{ $$ = $1;
445+
{ $$ = std::move($1);
446446
std::visit(overloaded {
447447
[&](std::string_view str) { $$.emplace_back(AttrName(state->symbols.create(str)), state->at(@2)); },
448448
[&](Expr * expr) {
@@ -457,20 +457,20 @@ attrs
457457
;
458458

459459
attrpath
460-
: attrpath '.' attr { $$ = $1; $$.push_back(AttrName(state->symbols.create($3))); }
460+
: attrpath '.' attr { $$ = std::move($1); $$.push_back(AttrName(state->symbols.create($3))); }
461461
| attrpath '.' string_attr
462-
{ $$ = $1;
462+
{ $$ = std::move($1);
463463
std::visit(overloaded {
464464
[&](std::string_view str) { $$.push_back(AttrName(state->symbols.create(str))); },
465465
[&](Expr * expr) { $$.push_back(AttrName(expr)); }
466-
}, $3);
466+
}, std::move($3));
467467
}
468468
| attr { $$.push_back(AttrName(state->symbols.create($1))); }
469469
| string_attr
470470
{ std::visit(overloaded {
471471
[&](std::string_view str) { $$.push_back(AttrName(state->symbols.create(str))); },
472472
[&](Expr * expr) { $$.push_back(AttrName(expr)); }
473-
}, $1);
473+
}, std::move($1));
474474
}
475475
;
476476

@@ -480,7 +480,7 @@ attr
480480
;
481481

482482
string_attr
483-
: '"' string_parts '"' { $$ = $2; }
483+
: '"' string_parts '"' { $$ = std::move($2); }
484484
| DOLLAR_CURLY expr '}' { $$ = $2; }
485485
;
486486

0 commit comments

Comments
 (0)