Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Str.comb(Regex) about 7x faster
Because we don't need to do an additional mapping from Match objects
to Str anymore.
  • Loading branch information
lizmat committed Oct 24, 2016
1 parent f09b8b7 commit 1794328
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/core/Str.pm
Expand Up @@ -390,12 +390,23 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}.new(self, $pat, $limit));
}
multi method comb(Str:D: Regex $pat, $limit = Inf, :$match) {
my $x;
$x = (1..$limit) unless nqp::istype($limit, Whatever) || $limit == Inf;
$match
?? self.match(:g, :$x, $pat)
!! self.match(:g, :$x, $pat).map: -> \match --> Str { match.Str }
multi method comb(Str:D: Regex:D $pattern, :$match) {
nqp::if(
$match,
self.match($pattern, :g),
self.match($pattern, :g, :r(Str))
)
}
multi method comb(Str:D: Regex:D $pattern, $limit, :$match) {
nqp::if(
nqp::istype($limit,Whatever) || $limit == Inf,
self.comb($pattern, :$match),
nqp::if(
$match,
self.match($pattern, :x(1..$limit)),
self.match($pattern, :x(1..$limit), :r(Str))
)
)
}

my $cursor-init := Cursor.^can("!cursor_init").AT-POS(0);
Expand Down

0 comments on commit 1794328

Please sign in to comment.