Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Slight optimization in Str / pick / roll
  • Loading branch information
lizmat committed Oct 3, 2013
1 parent a2bf0a4 commit d30b53e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/Baggy.pm
Expand Up @@ -53,7 +53,9 @@ my role Baggy does QuantHash {
!! $other.^does(self);
}

multi method Str(Baggy:D $ : --> Str) { ~ self.pairs.map({ .key xx .value }) }
multi method Str(Baggy:D $ : --> Str) {
~ %!elems.values.map({ .key xx .value });
}
multi method gist(Baggy:D $ : --> Str) {
my $name := self.^name;
( $name eq 'Bag' ?? 'bag' !! "$name.new" )
Expand All @@ -79,7 +81,7 @@ my role Baggy does QuantHash {

my $total = self.total;
my $picks = $total min $count;
my @pairs = self.pairs.map( { $_.key => $_.value } );;
my @pairs = %!elems.values.map( { $_.key => $_.value } );

map {
my $rand = $total.rand.Int;
Expand All @@ -100,7 +102,7 @@ my role Baggy does QuantHash {
method roll ($count = 1) {
my $total = self.total;
my $rolls = $count ~~ Num ?? $total min $count !! $count;
my @pairs := self.pairs;
my @pairs := %!elems.values;

map {
my $rand = $total.rand.Int;
Expand Down

0 comments on commit d30b53e

Please sign in to comment.