Skip to content

Commit

Permalink
Make sure Map.Hash works correctly
Browse files Browse the repository at this point in the history
Before, any subsequent changes made to the Hash, would be happening to
the Map also.  This also makes Map.Hash 15x faster for an empty Map,
to the same speed for a Map with 20 keys, to slower for larger Maps.
  • Loading branch information
lizmat committed Feb 7, 2016
1 parent 8588eeb commit 95e9655
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/core/Map.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP

multi method Hash(Map:U:) { Hash }
multi method Hash(Map:D:) {
my $hash := Hash.new;
nqp::bindattr($hash,Map,'$!storage',nqp::getattr(self,Map,'$!storage'));
$hash
if nqp::attrinited(self,Map,'$!storage') {
my $hash := nqp::create(Hash);
my $storage := nqp::bindattr($hash,Map,'$!storage',nqp::hash);
my $descriptor := nqp::null;
my $iter := nqp::iterator(nqp::getattr(self,Map,'$!storage'));
while $iter {
my $tmp := nqp::shift($iter);
nqp::bindkey($storage,nqp::iterkey_s($tmp),
nqp::p6scalarfromdesc($descriptor) =
nqp::decont(nqp::iterval($tmp)));
}
$hash
}
else {
nqp::create(Hash)
}
}

multi method Bool(Map:D:) {
Expand Down

0 comments on commit 95e9655

Please sign in to comment.