Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix breakage on JVM in the most awful way
By conditionally reverting to the map {} wrapper approach of before.  YUCK!
  • Loading branch information
lizmat committed Oct 21, 2014
1 parent f0efc88 commit 3687508
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/core/Baggy.pm
Expand Up @@ -159,36 +159,70 @@ my role Baggy does QuantHash {
my Int $seen;
my int $todo = ($keep ?? $count !! ($total min $count)) + 1;

#?if jvm
map {
my $selected is default(Nil);
#?endif
#?if !jvm
gather while $todo = $todo - 1 {
#?endif
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;

#?if jvm
$selected = $pair.key;
#?endif
#?if !jvm
take $pair.key;
#?endif
last if $keep;

$pair.value--;
$total = $total - 1;
last;
}
#?if jvm
$selected;
}, 2..$todo;
#?endif
#?if !jvm
}
#?endif
}

sub ROLLPICKGRABW($self,@pairs) is hidden_from_backtrace { # keep going
my Int $total = $self.total;
my Int $rand;
my Int $seen;

#?if jvm
map {
my $selected is default(Nil);
#?endif
#?if !jvm
gather loop {
#?endif
$rand = $total.rand.Int;
$seen = 0;
for @pairs -> $pair {
next if ( $seen += $pair.value ) <= $rand;
#?if jvm
$selected = $pair.key;
#?endif
#?if !jvm
take $pair.key;
#?endif
last;
}
#?if jvm
$selected;
}, *;
#?endif
#?if !jvm
}
#?endif
}

proto method classify-list(|) { * }
Expand Down

0 comments on commit 3687508

Please sign in to comment.