Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[01-regex.t] do a bit less caching

Putting all your previous calculations into a global hash is something
that the GC tends to frown upon. This (de-)optimisation relies on the
fact that the same regex is often repeated in contiguous regions, and
thus only the last regex need be cached.
  • Loading branch information...
commit c08bd97f16b2dd50bb763d4d7ef07ed2558043c8 1 parent 73a4257
@masak authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 t/perl6regex/01-regex.t
View
9 t/perl6regex/01-regex.t
@@ -2,7 +2,8 @@ use v6;
use Test;
use GGE;
-my %cached;
+my $previous-pattern = '';
+my $previous-rule;
sub dirname($path) { $path.comb(/<-[/]>+ '/'/).join() } #' (vim fix)
@@ -64,7 +65,11 @@ for @test-files -> $test-file {
}
sub match_perl6regex($pattern, $target) {
- my $rule = %cached{$pattern} //= GGE::Perl6Regex.new($pattern);
+ my $rule = $pattern eq $previous-pattern
+ ?? $previous-rule
+ !! GGE::Perl6Regex.new($pattern);
+ $previous-pattern = $pattern;
+ $previous-rule = $rule;
return $rule($target);
}
Please sign in to comment.
Something went wrong with that request. Please try again.