Skip to content

Commit

Permalink
improve performance of .ep templates slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 5, 2016
1 parent 2e394f9 commit f51f65c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

6.54 2016-03-04
6.54 2016-03-05
- Improved performance of .ep templates slightly.

6.53 2016-03-03
- Removed multi_accept setting from Hypnotoad.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -812,7 +812,7 @@ can be combined to solve some of hardest problems in web development.

=head2 Event loops

Internally the L<Mojo::IOLoop> event loop can use multiple reactor backends,
Internally, the L<Mojo::IOLoop> event loop can use multiple reactor backends,
L<EV> for example, will be automatically used if possible. Which in turn allows
other event loops like L<AnyEvent> to just work.

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -69,7 +69,7 @@ placeholder values are turned into a hash.
/user/show/23 -> /user/:action/:id -> {action => 'show', id => 23}

This hash is basically the center of every L<Mojolicious> application, you will
learn more about this later on. Internally routes get compiled to regular
learn more about this later on. Internally, routes get compiled to regular
expressions, so you can get the best of both worlds with a little bit of
experience.

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Plugin/EPRenderer.pm
Expand Up @@ -21,8 +21,7 @@ sub register {
my $name = $options->{inline} // $renderer->template_name($options);
return unless defined $name;
my @keys = sort grep {/^\w+$/} keys %{$c->stash};
my $key = md5_sum encode 'UTF-8', join(',', $name, @keys);
my $key = md5_sum encode 'UTF-8', $name;

# Prepare template for "epl" handler
my $cache = $renderer->cache;
Expand All @@ -35,7 +34,8 @@ sub register {

# Stash values (every time)
my $prepend = 'my $self = my $c = shift; my $_S = $c->stash; {';
$prepend .= join '', map {" my \$$_ = \$_S->{'$_'};"} @keys;
$prepend .= join '',
map {" my \$$_ = \$_S->{'$_'};"} grep {/^\w+$/} keys %{$c->stash};
$mt->prepend($prepend . $mt->prepend)->append(';}' . $mt->append);

$cache->set($key => $mt);
Expand Down

0 comments on commit f51f65c

Please sign in to comment.