Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Pair.new(key,value) about 4x as fast
  • Loading branch information
lizmat committed Oct 21, 2015
1 parent 26617f9 commit c6326d4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/core/Pair.pm
Expand Up @@ -2,15 +2,17 @@ my class Pair does Associative {
has $.key is default(Nil);
has $.value is rw is default(Nil);

multi method new(Mu $key, Mu \value) {
nqp::create(self).BUILD($key, value)
multi method new(Mu \key, Mu \value) {
my \p := nqp::create(self);
nqp::bindattr(p, Pair, '$!key', nqp::decont(key));
nqp::bindattr(p, Pair, '$!value', value);
p
}
multi method new(Mu :$key, Mu :$value) {
nqp::create(self).BUILD($key, $value)
}
method BUILD(Mu $!key, Mu \value) {
nqp::bindattr(self, Pair, '$!value', value);
self
my \p := nqp::create(self);
nqp::bindattr(p, Pair, '$!key', $key);
nqp::bindattr(p, Pair, '$!value', $value);
p
}

multi method ACCEPTS(Pair:D: %h) {
Expand Down

0 comments on commit c6326d4

Please sign in to comment.