Permalink
Browse files

Fix for RT #131561

R:Q.ADD-PAIRS-TO-MIX no longer has a SANITY step that weeded out the
0 weight elements before.  Instead, now do this on the fly.  Perhaps
a final iteration on the resulting hash would be more efficient in some
cases, but this feels better from a memory usage point of view.
  • Loading branch information...
lizmat committed Jun 13, 2017
1 parent 46b11f5 commit bf95bcb6c050bf7fbaa80d0754defc9d003fd072
Showing with 9 additions and 9 deletions.
  1. +9 −9 src/core/Rakudo/QuantHash.pm
@@ -629,9 +629,9 @@ my class Rakudo::QuantHash {
),
nqp::if(
nqp::istype($pulled,Pair),
nqp::unless( # got a Pair
nqp::if( # got a Pair
(my $value :=
nqp::decont(nqp::getattr($pulled,Pair,'$!value'))) == 0,
nqp::decont(nqp::getattr($pulled,Pair,'$!value'))),
nqp::if( # non-zero value
nqp::istype($value,Num) && nqp::isnanorinf($value),
X::OutOfRange.new( # NaN or -Inf or Inf, we're done
@@ -650,14 +650,14 @@ my class Rakudo::QuantHash {
elems,
(my $which := nqp::getattr($pulled,Pair,'$!key').WHICH)
),
nqp::stmts( # seen before, add value
(my $pair := nqp::atkey(elems,$which)),
nqp::bindattr(
$pair,
nqp::if( # seen before, add value
($value := nqp::getattr(
(my $pair := nqp::atkey(elems,$which)),
Pair,
'$!value',
nqp::getattr($pair,Pair,'$!value') + $value
)
'$!value'
) + $value),
nqp::bindattr($pair,Pair,'$!value',$value), # non-zero
nqp::deletekey(elems,$which) # zero
),
nqp::bindkey( # new, create new Pair
elems,

0 comments on commit bf95bcb

Please sign in to comment.