Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
since the loop in Str.match is not lazy anymore, use push instead of …
…gather/take; might be faster
  • Loading branch information
moritz committed Jul 24, 2011
1 parent b6150b2 commit 3867e02
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/core/Str.pm
Expand Up @@ -265,25 +265,24 @@ my class Str does Stringy {
?? ( $x.excludes_max ?? $x.max - 1 !! $x )
!! $x
}
my $taken = 0;
if $g || $overlap || $x.defined {
my @r = gather while my $m = $pat(Cursor.'!cursor_init'(self, |%opts)).MATCH {
my @r;
while my $m = $pat(Cursor.'!cursor_init'(self, |%opts)).MATCH {
# XXX a bug in the regex engine means that we can
# match a zero-width match past the end of the string.
# This is the workaround:
last if $m.to > self.chars;

take $m;
$taken++;
last if $taken == $x_upper;
@r.push: $m;
last if @r.elems == $x_upper;

# XXX should be %opts.delete('d'), but Hash.delete is NYI
%opts<d> = Any if %opts<d>;
%opts<c> = $overlap
?? $m.from +1
!! ($m.to == $m.from ?? $m.to + 1 !! $m.to);
}
return if $x.defined && $taken !~~ $x;
return if $x.defined && @r.elems !~~ $x;
return @r;
} else {
$pat(Cursor.'!cursor_init'(self, |%opts)).MATCH;
Expand Down

0 comments on commit 3867e02

Please sign in to comment.