Skip to content

Commit

Permalink
Get Baggy.AT-KEY optimization back into role
Browse files Browse the repository at this point in the history
We don't need no lexical, we can BEGIN  :-)
  • Loading branch information
lizmat committed May 22, 2017
1 parent ff04a37 commit accf519
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
8 changes: 0 additions & 8 deletions src/core/Bag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ my class Bag does Baggy {
)
}

my $p0 := nqp::p6bindattrinvres(nqp::create(Pair),Pair,'$!value',0);
multi method AT-KEY(Bag:D: \k) {
nqp::getattr(
nqp::ifnull(nqp::atkey(self.raw_hash,k.WHICH),$p0),
Pair,
'$!value'
)
}
multi method DELETE-KEY(Bag:D: \k) {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}
Expand Down
10 changes: 10 additions & 0 deletions src/core/Baggy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ my role Baggy does QuantHash {
0
)
}
multi method AT-KEY(Bag:D: \k) {
nqp::getattr(
nqp::ifnull(
nqp::atkey(self.raw_hash,k.WHICH),
BEGIN nqp::p6bindattrinvres(nqp::create(Pair),Pair,'$!value',0)
),
Pair,
'$!value'
)
}
multi method DELETE-KEY(Baggy:D: \k) {
nqp::if(
(my $raw := self.raw_hash)
Expand Down
8 changes: 0 additions & 8 deletions src/core/Mix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ my class Mix does Mixy {
)
}

my $p0 := nqp::p6bindattrinvres(nqp::create(Pair),Pair,'$!value',0);
multi method AT-KEY(Mix:D: \k) {
nqp::getattr(
nqp::ifnull(nqp::atkey(self.raw_hash,k.WHICH),$p0),
Pair,
'$!value'
)
}
multi method DELETE-KEY(Mix:D: \k) {
X::Immutable.new(method => 'DELETE-KEY', typename => self.^name).throw;
}
Expand Down

0 comments on commit accf519

Please sign in to comment.