Skip to content

Commit

Permalink
Add push-exactly methods to grep
Browse files Browse the repository at this point in the history
Should make some greps in some contexts faster
  • Loading branch information
lizmat committed Oct 11, 2015
1 parent be66ad4 commit 9b86933
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/core/Any-iterable-methods.pm
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,17 @@ augment class Any {
until ($value := $!iter.pull-one) =:= IterationEnd;
IterationEnd
}
method push-exactly($target, int $n) {
my Mu $value;
my int $done;
until IterationEnd =:= ($value := $!iter.pull-one) {
if $value.match($!test) {
$target.push($value);
return $done unless ($done = $done + 1) < $n;
}
}
IterationEnd
}
method push-all($target) {
my Mu $value;
$target.push($value) if $value.match($!test)
Expand All @@ -347,11 +358,28 @@ augment class Any {
until ($value := $!iter.pull-one) =:= IterationEnd;
IterationEnd # in case of last
}
method push-exactly($target, int $n) {
my Mu $value;
my int $done;
until IterationEnd =:= ($value := $!iter.pull-one) {
if $!test($value) {
$target.push($value);
return $done unless ($done = $done + 1) < $n;
}
}
IterationEnd
}
method push-all($target) {
my Mu $value;
$target.push($value) if $!test($value)
until ($value := $!iter.pull-one) =:= IterationEnd;
IterationEnd # in case of last
IterationEnd
}
method sink-all() {
my Mu $value;
$!test($value)
until ($value := $!iter.pull-one) =:= IterationEnd;
IterationEnd
}
}.new(self, $test))
} else {
Expand Down Expand Up @@ -387,6 +415,17 @@ augment class Any {
until ($value := $!iter.pull-one) =:= IterationEnd;
IterationEnd
}
method push-exactly($target, int $n) {
my Mu $value;
my int $done;
until IterationEnd =:= ($value := $!iter.pull-one) {
if $!test.ACCEPTS($value) {
$target.push($value);
return $done unless ($done = $done + 1) < $n;
}
}
IterationEnd
}
method push-all($target) {
my Mu $value;
$target.push($value) if $!test.ACCEPTS($value)
Expand Down

0 comments on commit 9b86933

Please sign in to comment.