File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -1264,10 +1264,15 @@ There are four ways you can interpolate a string into regex as a pattern.
12641264That is using C « $pattern » , C « $($pattern) » , C « <$pattern> » or
12651265C « <{$pattern.method}> » .
12661266
1267+ If the variable to be interpolated is statically typed as a C « Str » or C « str »
1268+ (like C « $pattern0 » and C « $pattern2 » are below) and only interpolated literally
1269+ (like the first example below), than the compiler can optimize that and it runs
1270+ much faster.
1271+
12671272 my Str $text = 'camelia';
12681273 my Str $pattern0 = 'camelia';
1269- my Str $pattern1 = 'ailemac';
1270- my Str $pattern2 = '\w+';
1274+ my $pattern1 = 'ailemac';
1275+ my str $pattern2 = '\w+';
12711276
12721277 say $text ~~ / $pattern0 /; # OUTPUT: «「camelia」»
12731278 say $text ~~ / $($pattern0) /; # OUTPUT: «「camelia」»
You can’t perform that action at this time.
0 commit comments