From a1aa3e31db520755c25a0f2e1a2bedcc46ebea8f Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 14 Jun 2021 14:01:36 -0700 Subject: [PATCH] Markdown.pl: tidy up some regex options The %g_escape_table hash gets initialized in a BEGIN block and then remains constant for the life of Markdown.pl. Add the "o" (compile pattern once) option to all the patterns that it appears in to perhaps squeeze out just a tiny little bit of extra performance if possible. Signed-off-by: Kyle J. McKay --- Markdown.pl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 10a6f1d..666a0c9 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1835,7 +1835,7 @@ sub _EscapeSpecialChars { # corresponding block id value; this is likely # overkill, but it should prevent us from colliding # with the escape values by accident. - $cur_token->[1] =~ s!([*_~])!$g_escape_table{$1}!g; + $cur_token->[1] =~ s!([*_~])!$g_escape_table{$1}!go; $text .= $cur_token->[1]; } else { my $t = $cur_token->[1]; @@ -1989,7 +1989,7 @@ sub _MakeATag { $text = _DoItalicsAndBoldAndStrike($text); # We've got to encode any of these remaining to avoid # conflicting with other italics, bold and strike through and links. - $text =~ s!([]*_~[])!$g_escape_table{$1}!g; + $text =~ s!([]*_~[])!$g_escape_table{$1}!go; $result .= " title=\"" . _EncodeAttText($title) . "\"" if $title ne ""; return $result . $g_escape_table{'>'} . $text . $g_escape_table{'<'}."/a".$g_escape_table{'>'}; @@ -2385,7 +2385,7 @@ sub _EncodeAttText { $text = escapeXML(_strip($text)); # We've got to encode these to avoid conflicting # with italics, bold and strike through. - $text =~ s!([*_~:])!$g_escape_table{$1}!g; + $text =~ s!([*_~:])!$g_escape_table{$1}!go; return $text; } @@ -3125,7 +3125,7 @@ sub _EncodeCode { s! > !>!gx; # Now, escape characters that are magic in Markdown: - s!([*_~{}\[\]\\])!$g_escape_table{$1}!g; + s!([*_~{}\[\]\\])!$g_escape_table{$1}!go; return $_; } @@ -3140,7 +3140,7 @@ sub _DoItalicsAndBoldAndStrike { {$1}gsx; # We've got to encode any of these remaining to # avoid conflicting with other italics and bold. - $text =~ s!([*])!$g_escape_table{$1}!g; + $text =~ s!([*])!$g_escape_table{$1}!go; $text; }; my $doital2 = sub { @@ -3149,7 +3149,7 @@ sub _DoItalicsAndBoldAndStrike { {$1}gsx; # We've got to encode any of these remaining to # avoid conflicting with other italics and bold. - $text =~ s!([_])!$g_escape_table{$1}!g; + $text =~ s!([_])!$g_escape_table{$1}!go; $text; }; @@ -4074,7 +4074,7 @@ sub _EncodeBackslashEscapes { local $_ = shift; s!\\\\!$g_escape_table{'\\'}!go; # Must process escaped backslashes first. - s{\\([`*_~{}\[\]()>#+\-.!`])}{$g_escape_table{$1}}g; + s{\\([`*_~{}\[\]()>#+\-.!`])}{$g_escape_table{$1}}go; return $_; }