Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed Feb 19, 2013
1 parent 9d054d1 commit 495937f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/Mojo/Template.pm
Expand Up @@ -180,20 +180,18 @@ sub parse {
# Perl line
if ($state eq 'text' && $line !~ s/^(\s*)\Q$start$replace\E/$1$start/) {
if ($line =~ s/^(\s*)\Q$start\E(?:(\Q$cmnt\E)|(\Q$expr\E))?//) {
if ($2) { $line = "$tag$cmnt $trim$end" }
else { $line = $3 ? "$1$tag$3$line $end" : "$tag$line $trim$end" }

# Comment
if ($2) { $line = "$tag$2 $trim$end" }

# Expression or code
else { $line = $3 ? "$1$tag$3$line $end" : "$tag$line $trim$end" }
}
}

# Escaped line ending
if ($line =~ /(\\+)$/) {
my $len = length $1;

# Newline
if ($len == 1) { $line =~ s/\\$// }

# Backslash
elsif ($len > 1) { $line =~ s/\\\\$/\\\n/ }
length $1 > 1 ? ($line =~ s/\\\\$/\\\n/) : ($line =~ s/\\$//);
}

# Normal line ending
Expand Down Expand Up @@ -235,7 +233,7 @@ sub parse {
# Comment
elsif ($token =~ /^\Q$tag$cmnt\E$/) { $state = 'cmnt' }

# Value
# Text
else {

# Replace
Expand Down

0 comments on commit 495937f

Please sign in to comment.