Skip to content

Commit

Permalink
Slight performance improvement, avoid useless costy calls to getAttri…
Browse files Browse the repository at this point in the history
…bute

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Feb 24, 2021
1 parent e76c70b commit 283673f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ public function compile(Compiler $compiler)
$compiler->raw('), array(');

foreach ($vars as $var) {
if ($var->getAttribute('name') === 'count') {
$attributeName = $var->getAttribute('name');
if ($attributeName === 'count') {
$compiler
->string('%count%')
->raw(' => abs(')
->subcompile($this->getNode('count'))
->raw('), ');
} else {
$compiler
->string('%' . $var->getAttribute('name') . '%')
->string('%' . $attributeName . '%')
->raw(' => ')
->subcompile($var)
->raw(', ');
Expand Down Expand Up @@ -233,8 +234,9 @@ protected function compileString(Node $body): array
while ($n instanceof CheckToStringNode) {
$n = $n->getNode('expr');
}
$msg .= sprintf('%%%s%%', $n->getAttribute('name'));
$vars[] = new NameExpression($n->getAttribute('name'), $n->getTemplateLine());
$attributeName = $n->getAttribute('name');
$msg .= sprintf('%%%s%%', $attributeName);
$vars[] = new NameExpression($attributeName, $n->getTemplateLine());
} else {
$msg .= $node->getAttribute('data');
}
Expand Down

0 comments on commit 283673f

Please sign in to comment.