Skip to content

Commit 42dc344

Browse files
committed
Micro-optimize &rewrite-url routine
1 parent dc5c9e2 commit 42dc344

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

lib/Pod/Htmlify.pm6

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,31 @@ sub unescape-percent($s) {
3737
}
3838

3939
sub rewrite-url($s) is export {
40-
state %cache;
40+
state %cache =
41+
'/routine//' => '/routine/' ~ replace-badchars-with-goodnames('/'),
42+
'/routine///' => '/routine/' ~ replace-badchars-with-goodnames('//');
4143
return %cache{$s} if %cache{$s}:exists;
44+
4245
my Str $r;
4346
given $s {
44-
when / ^ [ 'http' | 'https' | 'irc' ] '://' / {
45-
# external link, we bail
46-
return $s;
47-
}
48-
49-
when / ^ '#' / {
50-
# on-page link, we bail
51-
return $s;
47+
# Avoiding Junctions as matchers due to:
48+
# https://github.com/rakudo/rakudo/issues/1385#issuecomment-377895230
49+
when { .starts-with: 'https://' or .starts-with: '#'
50+
or .starts-with: 'http://' or .starts-with: 'irc://'
51+
} {
52+
return %cache{$s} = $s; # external link or on-page-link, we bail
5253
}
5354
# Type
54-
when / ^ <[A..Z]> / {
55+
when 'A'.ord*.ord'Z'.ord {
5556
$r = "/type/{replace-badchars-with-goodnames(unescape-percent($s))}";
56-
succeed;
5757
}
5858
# Routine
5959
when / ^ <[a..z]> | ^ <-alpha>* $ / {
6060
$r = "/routine/{replace-badchars-with-goodnames(unescape-percent($s))}";
61-
succeed;
6261
}
63-
64-
# Special case the really nasty ones
65-
when / ^ '/routine//' $ / { return '/routine/' ~ replace-badchars-with-goodnames('/'); succeed; }
66-
when / ^ '/routine///' $ / { return '/routine/' ~ replace-badchars-with-goodnames('//'); succeed; }
67-
6862
when / ^
6963
([ '/routine/' | '/syntax/' | '/language/' | '/programs/' | '/type/' ]) (<-[#/]>+) [ ('#') (<-[#]>*) ]* $ / {
7064
$r = $0 ~ replace-badchars-with-goodnames(unescape-percent($1)) ~ $2 ~ uri_escape($3);
71-
succeed;
7265
}
7366

7467
default {

0 commit comments

Comments
 (0)