Skip to content

Commit

Permalink
Use --/++$i instead of $i = nqp::add/sub_i($i,1)
Browse files Browse the repository at this point in the history
Associative related
  • Loading branch information
lizmat committed Feb 16, 2022
1 parent a6019d5 commit 8109932
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/core.c/Hash/Object.pm6
Expand Up @@ -120,8 +120,7 @@ my role Hash::Object[::TValue, ::TKey] does Associative[TValue] {
(my int $i = -1),
nqp::while(
iterator,
nqp::bindpos(buffer,($i = nqp::add_i($i,1)),
nqp::iterval(nqp::shift(iterator)))
nqp::bindpos(buffer,++$i,nqp::iterval(nqp::shift(iterator)))
)
)
);
Expand Down Expand Up @@ -189,7 +188,7 @@ my role Hash::Object[::TValue, ::TKey] does Associative[TValue] {
nqp::add_i(nqp::floor_n(nqp::rand_n(nqp::elems(storage))),1)),
(my \iter := nqp::iterator(storage)),
nqp::while(
nqp::shift(iter) && ($i = nqp::sub_i($i,1)),
nqp::shift(iter) && --$i,
nqp::null
),
nqp::iterval(iter)
Expand Down
12 changes: 6 additions & 6 deletions src/core.c/Map.pm6
Expand Up @@ -68,7 +68,7 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
(my int $i = -1),
nqp::while(
iterator,
nqp::bindpos(buffer,($i = nqp::add_i($i,1)),
nqp::bindpos(buffer,++$i,
Pair.new(
nqp::iterkey_s(nqp::shift(iterator)),
nqp::iterval(iterator)
Expand Down Expand Up @@ -114,7 +114,7 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
has int $!i = -1;
method pull-one() {
nqp::if(
nqp::islt_i(($!i = nqp::add_i($!i,1)),nqp::elems($!keys)),
nqp::islt_i(++$!i,nqp::elems($!keys)),
nqp::stmts(
(my \key := nqp::atpos_s($!keys,$!i)),
Pair.new(key,nqp::atkey($!map,key))
Expand All @@ -127,7 +127,7 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
my \keys := $!keys;
my int $i = $!i;
nqp::while(
nqp::islt_i(($i = nqp::add_i($i,1)),nqp::elems(keys)),
nqp::islt_i(++$i,nqp::elems(keys)),
nqp::stmts(
(my \key := nqp::atpos_s(keys,$i)),
$target.push(Pair.new(key,nqp::atkey(map,key)))
Expand Down Expand Up @@ -542,7 +542,7 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
nqp::add_i(nqp::floor_n(nqp::rand_n(nqp::elems($!storage))),1)),
(my \iter := nqp::iterator($!storage)),
nqp::while(
nqp::shift(iter) && ($i = nqp::sub_i($i,1)),
nqp::shift(iter) && --$i,
nqp::null
),
Pair.new(nqp::iterkey_s(iter),nqp::iterval(iter))
Expand All @@ -569,7 +569,7 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
$!pairs := nqp::setelems(nqp::list,$i);

nqp::while(
nqp::isge_i(($i = nqp::sub_i($i,1)),0),
nqp::isge_i(--$i,0),
nqp::bindpos_s($!keys,$i,
nqp::iterkey_s(nqp::shift(iter)))
);
Expand Down Expand Up @@ -653,7 +653,7 @@ multi sub infix:<eqv>(Map:D \a, Map:D \b --> Bool:D) {
nqp::iterval(nqp::shift(iter)),
nqp::ifnull(nqp::atkey(bmap,nqp::iterkey_s(iter)),NotEQV)
),
($elems = nqp::sub_i($elems,1))
--$elems
),
nqp::not_i($elems) # ok if none left
),
Expand Down

0 comments on commit 8109932

Please sign in to comment.