Skip to content

Commit

Permalink
Add skip-one method to appropriate PredictiveIterators
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Sep 23, 2018
1 parent b22edce commit e54885e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/core/Rakudo/Iterator.pm6
Expand Up @@ -705,6 +705,7 @@ class Rakudo::Iterator {
?? nqp::chr($!i)
!! IterationEnd
}
method skip-one() { ( $!i = $!i + 1 ) <= $!n }
method push-all($target --> IterationEnd) {
my int $i = $!i;
my int $n = $!n;
Expand Down Expand Up @@ -1876,6 +1877,7 @@ class Rakudo::Iterator {
IterationEnd
)
}
method skip-one() { nqp::isle_i(($!i = nqp::add_i($!i,1)),$!last) }
method push-exactly($target, int $batch-size) {
nqp::stmts(
(my int $todo = nqp::add_i($batch-size,1)),
Expand Down Expand Up @@ -2650,7 +2652,6 @@ class Rakudo::Iterator {
)
)
}

method push-exactly($target, int $batch-size) {
nqp::stmts(
(my int $todo = nqp::add_i($batch-size,1)),
Expand Down Expand Up @@ -3674,6 +3675,7 @@ class Rakudo::Iterator {
nqp::p6bindattrinvres(nqp::create(self),self,'$!value',value)
}
method pull-one() is raw { $!value }
method skip-one(--> True) { }
method sink-all(--> IterationEnd) { }
method count-only(--> Inf) { }
method bool-only(--> True) { }
Expand Down
6 changes: 3 additions & 3 deletions src/core/Range.pm6
Expand Up @@ -180,9 +180,8 @@ my class Range is Cool does Iterable does Positional {
method !SET-SELF(\i,\n) { $!i = i + 1; $!n = n; self }
method new(\i,\n) { nqp::create(self)!SET-SELF(i,n) }

method pull-one() {
( $!i = $!i - 1 ) >= $!n ?? $!i !! IterationEnd
}
method pull-one() { ( $!i = $!i - 1 ) >= $!n ?? $!i !! IterationEnd }
method skip-one() { ( $!i = $!i - 1 ) >= $!n }
method push-all($target --> IterationEnd) {
my int $i = $!i;
my int $n = $!n;
Expand Down Expand Up @@ -224,6 +223,7 @@ my class Range is Cool does Iterable does Positional {
?? nqp::chr($!i)
!! IterationEnd
}
method skip-one() { ( $!i = $!i - 1 ) >= $!n }
method push-all($target --> IterationEnd) {
my int $i = $!i;
my int $n = $!n;
Expand Down
3 changes: 3 additions & 0 deletions src/core/Shaped1Array.pm6
Expand Up @@ -192,6 +192,9 @@
IterationEnd
)
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::elems($!reified))
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my int $elems = nqp::elems($!reified)),
Expand Down
3 changes: 3 additions & 0 deletions src/core/Str.pm6
Expand Up @@ -359,6 +359,9 @@ my class Str does Stringy { # declared in BOOTSTRAP
IterationEnd
)
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),$!chars)
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my str $str = $!str), # locals are faster
Expand Down
3 changes: 3 additions & 0 deletions src/core/Uni.pm6
Expand Up @@ -31,6 +31,9 @@ my class Uni does Positional[uint32] does Stringy is repr('VMArray') is array_ty
IterationEnd
)
}
method skip-one {
nqp::islt_i(($!i = nqp::add_i($!i, 1)), $!els)
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my $uni := $!uni), # lexicals faster than attrs
Expand Down
15 changes: 12 additions & 3 deletions src/core/native_array.pm6
Expand Up @@ -1658,7 +1658,7 @@ my class array does Iterable {
}

#- start of generated part of shapedintarray role -----------------------------
#- Generated on 2018-09-12T23:22:29+02:00 by tools/build/makeNATIVE_SHAPED_ARRAY.p6
#- Generated on 2018-09-23T11:51:05+02:00 by tools/build/makeNATIVE_SHAPED_ARRAY.p6
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

role shapedintarray does shapedarray {
Expand Down Expand Up @@ -2037,6 +2037,9 @@ my class array does Iterable {
IterationEnd
)
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::elems($!list))
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my int $elems = nqp::elems($!list)),
Expand Down Expand Up @@ -2218,7 +2221,7 @@ my class array does Iterable {
#- end of generated part of shapedintarray role -------------------------------

#- start of generated part of shapednumarray role -----------------------------
#- Generated on 2018-09-12T23:22:29+02:00 by tools/build/makeNATIVE_SHAPED_ARRAY.p6
#- Generated on 2018-09-23T11:51:05+02:00 by tools/build/makeNATIVE_SHAPED_ARRAY.p6
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

role shapednumarray does shapedarray {
Expand Down Expand Up @@ -2597,6 +2600,9 @@ my class array does Iterable {
IterationEnd
)
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::elems($!list))
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my int $elems = nqp::elems($!list)),
Expand Down Expand Up @@ -2778,7 +2784,7 @@ my class array does Iterable {
#- end of generated part of shapednumarray role -------------------------------

#- start of generated part of shapedstrarray role -----------------------------
#- Generated on 2018-09-12T23:22:29+02:00 by tools/build/makeNATIVE_SHAPED_ARRAY.p6
#- Generated on 2018-09-23T11:51:05+02:00 by tools/build/makeNATIVE_SHAPED_ARRAY.p6
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

role shapedstrarray does shapedarray {
Expand Down Expand Up @@ -3157,6 +3163,9 @@ my class array does Iterable {
IterationEnd
)
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::elems($!list))
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my int $elems = nqp::elems($!list)),
Expand Down
3 changes: 3 additions & 0 deletions tools/build/makeNATIVE_SHAPED_ARRAY.p6
Expand Up @@ -420,6 +420,9 @@ for $*IN.lines -> $line {
IterationEnd
)
}
method skip-one() {
nqp::islt_i(($!pos = nqp::add_i($!pos,1)),nqp::elems($!list))
}
method push-all($target --> IterationEnd) {
nqp::stmts(
(my int $elems = nqp::elems($!list)),
Expand Down

0 comments on commit e54885e

Please sign in to comment.