Skip to content

Commit

Permalink
Second pass on fixing .count-only/.bool-only issues
Browse files Browse the repository at this point in the history
- Fixes .count-only not updating in Hash.kv iterator
- Fixes .count-only/.bool-only returning wrong values when
    the last .pull-one (the one that gives IterationEnd) is called

First pass was done in:
af9812fa73292723871
  • Loading branch information
zoffixznet committed Dec 10, 2017
1 parent 1dbf5f5 commit 0e228fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
3 changes: 0 additions & 3 deletions src/core/Map.pm
Expand Up @@ -206,9 +206,6 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
)
)
}
method count-only() {
nqp::mul_i(nqp::elems($!hash),2)
}
}.new(self))
}
multi method antipairs(Map:D:) {
Expand Down
36 changes: 25 additions & 11 deletions src/core/Rakudo/Iterator.pm
Expand Up @@ -53,13 +53,17 @@ class Rakudo::Iterator {
}
method count-only() {
# we start off $!i at -1, so add back 1 to it to get right count
# if $i is >= elems, that means we're done iterating. We can't
# *just* substract in that case, as we'd get `-1`
nqp::p6box_i(
nqp::sub_i(nqp::elems($!blob),nqp::add_i($!i,1)))
nqp::if(
nqp::islt_i($!i, nqp::elems($!blob)),
nqp::sub_i(nqp::elems($!blob),nqp::add_i($!i,1)),
0))
}
method bool-only() {
# we start off $!i at -1, so add back 1 to it to get right count
nqp::p6bool(
nqp::sub_i(nqp::elems($!blob),nqp::add_i($!i,1)))
nqp::islt_i($!i, nqp::sub_i(nqp::elems($!blob),1)))
}
method sink-all(--> IterationEnd) { $!i = nqp::elems($!blob) }
}
Expand Down Expand Up @@ -2393,8 +2397,10 @@ class Rakudo::Iterator {
IterationEnd
)
}
method count-only { nqp::p6box_i($!todo) }
method bool-only { nqp::p6bool($!todo) }
method count-only {
nqp::isge_i($!todo, 0) ?? nqp::p6box_i($!todo) !! 0
}
method bool-only { nqp::p6bool(nqp::isgt_i($!todo, 0)) }
}.new($n,$b)
)
)
Expand Down Expand Up @@ -2472,13 +2478,17 @@ class Rakudo::Iterator {
}
method count-only() {
# we start off $!i at -1, so add back 1 to it to get right count
# if $i is >= elems, that means we're done iterating. We can't
# *just* substract in that case, as we'd get `-1`
nqp::p6box_i(
nqp::sub_i(nqp::elems($!reified),nqp::add_i($!i,1)))
nqp::if(
nqp::islt_i($!i, nqp::elems($!reified)),
nqp::sub_i(nqp::elems($!reified),nqp::add_i($!i,1)),
0))
}
method bool-only() {
# we start off $!i at -1, so add back 1 to it to get right count
nqp::p6bool(
nqp::sub_i(nqp::elems($!reified),nqp::add_i($!i,1)))
nqp::islt_i($!i, nqp::sub_i(nqp::elems($!reified),1)))
}
method sink-all(--> IterationEnd) { $!i = nqp::elems($!reified) }
}.new(array, descriptor)
Expand Down Expand Up @@ -2546,13 +2556,17 @@ class Rakudo::Iterator {
}
method count-only() {
# we start off $!i at -1, so add back 1 to it to get right count
# if $i is >= elems, that means we're done iterating. We can't
# *just* substract in that case, as we'd get `-1`
nqp::p6box_i(
nqp::sub_i(nqp::elems($!reified),nqp::add_i($!i,1)))
nqp::if(
nqp::islt_i($!i, nqp::elems($!reified)),
nqp::sub_i(nqp::elems($!reified),nqp::add_i($!i,1)),
0))
}
method bool-only() {
# we start off $!i at -1, so add back 1 to it to get right count
nqp::p6bool(
nqp::sub_i(nqp::elems($!reified),nqp::add_i($!i,1)))
nqp::islt_i($!i, nqp::sub_i(nqp::elems($!reified),1)))
}
method sink-all(--> IterationEnd) { $!i = nqp::elems($!reified) }
}.new(list)
Expand Down

0 comments on commit 0e228fa

Please sign in to comment.