Skip to content
Browse files

Slight optimization in Str / pick / roll

  • Loading branch information...
1 parent a2bf0a4 commit d30b53e4b9c46bb634e2673954f20279d23ec528 @lizmat lizmat committed
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/core/Baggy.pm
View
8 src/core/Baggy.pm
@@ -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" )
@@ -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;
@@ -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;

0 comments on commit d30b53e

Please sign in to comment.
Something went wrong with that request. Please try again.