Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Streamline Map.STORE: making it 10% faster
  • Loading branch information
lizmat committed Mar 13, 2016
1 parent b6f3ecd commit 24d42d1
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/core/Map.pm
Expand Up @@ -199,24 +199,25 @@ my class Map does Iterable does Associative { # declared in BOOTSTRAP
}

method STORE(\to_store) {
my \iter = to_store.iterator;
$!storage := nqp::hash();
until (my Mu $x := iter.pull-one) =:= IterationEnd {
if nqp::istype($x,Pair) {
self.STORE_AT_KEY($x.key, $x.value)
}
elsif nqp::istype($x, Map) and !nqp::iscont($x) {
for $x.list { self.STORE_AT_KEY(.key, .value) }
}
elsif !((my Mu $y := iter.pull-one) =:= IterationEnd) {
self.STORE_AT_KEY($x, $y)
}
else {
nqp::istype($x,Failure)
?? $x.throw
!! X::Hash::Store::OddNumber.new.throw;
}
method !STORE_LIST(\x --> Nil) {
self.STORE_AT_KEY(.key,.value) for x.list;
}

$!storage := nqp::hash();
my $iter := to_store.iterator;
my Mu $x;
my Mu $y;

nqp::istype($x,Pair)
?? self.STORE_AT_KEY($x.key, $x.value)
!! nqp::istype($x, Map) && !nqp::iscont($x)
?? self!STORE_LIST($x)
!! (($y := $iter.pull-one) =:= IterationEnd)
?? nqp::istype($x,Failure)
?? $x.throw
!! X::Hash::Store::OddNumber.new.throw
!! self.STORE_AT_KEY($x,$y)
until ($x := $iter.pull-one) =:= IterationEnd;
self
}

Expand Down

0 comments on commit 24d42d1

Please sign in to comment.