Skip to content

Commit

Permalink
Make Hash[Any,Any].ASSIGN-KEY about 15% faster
Browse files Browse the repository at this point in the history
- rewritten using nqp ops
- smarter handling of empty typed hashes

Almost not worth it, but such a basic functionality can use all the
optimization it can get
  • Loading branch information
lizmat committed Jul 23, 2016
1 parent 79f9be1 commit e5c909c
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/core/Hash.pm
Expand Up @@ -544,18 +544,29 @@ my class Hash { # declared in BOOTSTRAP
}

method ASSIGN-KEY(::?CLASS:D: TKey \key, TValue \assignval) {
nqp::bindattr(self,Map,'$!storage',nqp::hash)
unless nqp::defined(nqp::getattr(self,Map,'$!storage'));
my str $which = key.WHICH;

nqp::existskey(nqp::getattr(self,Map,'$!storage'),$which)
?? (nqp::getattr(
nqp::atkey(nqp::getattr(self,Map,'$!storage'),$which),
Pair, '$!value') = assignval)
!! nqp::bindkey(nqp::getattr(self,Map,'$!storage'),$which,
Pair.new(key,nqp::p6scalarfromdesc(
nqp::getattr(self,Hash,'$!descriptor')) = assignval));
assignval
nqp::if(
nqp::getattr(self,Map,'$!storage').DEFINITE,
nqp::if(
nqp::existskey(nqp::getattr(self,Map,'$!storage'),
my str $which = nqp::unbox_s(key.WHICH)),
(nqp::getattr(
nqp::atkey(nqp::getattr(self,Map,'$!storage'),$which),
Pair,'$!value') = assignval),
nqp::stmts(
(nqp::bindkey(nqp::getattr(self,Map,'$!storage'),$which,
Pair.new(key,nqp::p6scalarfromdesc(
nqp::getattr(self,Hash,'$!descriptor')) = assignval))),
assignval
)
),
nqp::stmts(
(nqp::bindkey(nqp::bindattr(self,Map,'$!storage',nqp::hash),
nqp::unbox_s(key.WHICH),
Pair.new(key,nqp::p6scalarfromdesc(
nqp::getattr(self,Hash,'$!descriptor')) = assignval))),
assignval
)
)
}

method BIND-KEY(TKey \key, TValue \bindval) is raw {
Expand Down

0 comments on commit e5c909c

Please sign in to comment.