Skip to content

Instantly share code, notes, and snippets.

/text.diff Secret

Created August 31, 2014 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a0e9be83289c4d796711 to your computer and use it in GitHub Desktop.
Save anonymous/a0e9be83289c4d796711 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Template.pm b/lib/Mojo/Template.pm
index ed84f8b..168900e 100644
--- a/lib/Mojo/Template.pm
+++ b/lib/Mojo/Template.pm
@@ -226,6 +226,13 @@ sub parse {
push @$tree, \@token;
}
+ # Optimize successive text lines
+ my $i = 0;
+ while ((my $current = $tree->[$i]) && (my $next = $tree->[$i + 1])) {
+ ++$i and next if grep { @$_ != 2 || $_->[0] ne 'text' } $current, $next;
+ splice @$tree, $i, 2, ['text', $current->[1] . $next->[1]];
+ }
+
return $self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment