Skip to content

Commit

Permalink
Simplify Mappy-kv-from-pairs.pull-one a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed May 2, 2017
1 parent 8088f08 commit 45305ec
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/core/Rakudo/Iterator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Rakudo::Iterator {
our role Mappy-kv-from-pairs does Iterator {
has $!storage;
has $!iter;
has Mu $!value;
has $!on;

method SET-SELF(\hash) {
nqp::stmts(
Expand All @@ -110,18 +110,16 @@ class Rakudo::Iterator {

method pull-one() is raw {
nqp::if(
$!value.DEFINITE,
$!on,
nqp::stmts(
(my $tmp := $!value),
($!value := nqp::null),
$tmp
($!on := 0),
nqp::getattr(nqp::iterval($!iter),Pair,'$!value')
),
nqp::if(
$!iter,
nqp::stmts(
($tmp := nqp::decont(nqp::iterval(nqp::shift($!iter)))),
($!value := nqp::getattr($tmp,Pair,'$!value')),
(nqp::getattr($tmp,Pair,'$!key'))
($!on := 1),
nqp::getattr(nqp::iterval(nqp::shift($!iter)),Pair,'$!key')
),
IterationEnd
)
Expand All @@ -139,20 +137,13 @@ class Rakudo::Iterator {
}
method skip-one() { # must define our own skip-one
nqp::if(
$!value.DEFINITE,
nqp::stmts(
($!value := nqp::null),
1
),
$!on,
nqp::not_i($!on := 0),
nqp::if(
$!iter,
nqp::stmts(
($!value := nqp::getattr(
nqp::decont(nqp::iterval(nqp::shift($!iter))),
Pair,
'$!value'
)),
1
nqp::shift($!iter),
($!on := 1)
)
)
)
Expand Down

0 comments on commit 45305ec

Please sign in to comment.