Skip to content

Commit

Permalink
Avoid a dummy sub in Template::Parser
Browse files Browse the repository at this point in the history
This is an optimization which avoids creating
an anonymous sub then call it inside an eval
block.
  • Loading branch information
atoomic committed Oct 5, 2018
1 parent 6bb4332 commit 1c99969
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/Template/Parser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -954,22 +954,27 @@ sub _parse {
or $status = ACCEPT;

# use dummy sub if code ref doesn't exist
$code = sub { $_[1] }
unless $code;

@codevars = $len
? map { $_->[1] } @$stack[ -$len .. -1 ]
: ();

eval {
$coderet = &$code( $self, @codevars );
};
if ($@) {
my $err = $@;
chomp $err;
return $self->_parse_error($err);
if ( !$code ) {
$coderet = $len ? $stack->[ -$len ]->[1] : undef;
} else {
# $code = sub { $_[1] }
# unless $code;

@codevars = $len
? map { $_->[1] } @$stack[ -$len .. -1 ]
: ();

eval {
$coderet = &$code( $self, @codevars );
};
if ($@) {
my $err = $@;
chomp $err;
return $self->_parse_error($err);
}
}


# reduce stack by $len
splice(@$stack, -$len, $len);

Expand Down

0 comments on commit 1c99969

Please sign in to comment.