Browse Source

Markdown.pl: claw back another minor performance gain

Revise _DeTab yet again to provide a minor boost.

This really does currently seem to be the fastest detab mechanism
available.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 5 years ago
parent
commit
9593c956c1
  1. 20
      Markdown.pl

20
Markdown.pl

@ -2840,28 +2840,16 @@ sub _DeTab {
my $ans = ""; my $ans = "";
while (pos($text) < $end) { while (pos($text) < $end) {
my $line; my $line;
if ($text =~ /\G([^\n]*\n)/gc) { if ($text =~ /\G(.*?\n)/gcs) {
$line = $1; $line = $1;
} else { } else {
$line = substr($text, pos($text)); $line = substr($text, pos($text));
pos($text) = $end; pos($text) = $end;
} }
$line =~ s/$spr// if $leadsp; $line =~ s/$spr// if $leadsp;
my $eline = length($line); # From the Perl camel book section "Fluent Perl" but modified a bit
pos($line) = 0; $line =~ s/(.*?)(\t+)/$1 . ' ' x (length($2) * $ts - length($1) % $ts)/ges;
my $xline = ""; $ans .= $line;
while (pos($line) < $eline) {
if ($line =~ /\G([^\t]+)/gc) {
$xline .= $1;
next;
}
if ($line =~ /\G(\t+)/gc) {
$xline .= ' ' x (length($1) * $ts - (length($xline) % $ts));
next;
}
die "programmer error"; # cannot get here
}
$ans .= $xline;
} }
return $ans; return $ans;
} }

Loading…
Cancel
Save