Skip to content
Permalink
Browse files

Allow Nil to be assigned to object Hashes

- don't let the typecheck on ASSIGN-KEY do the work
- let the actual assignment do the type check for better diagnostics
- also allows Nil to be assigned
- also assignment of existing key 20% faster
  • Loading branch information...
lizmat committed Oct 8, 2018
1 parent 560e94e commit f61ba41a286cee3dc1765714a4657e8dffb9a181
Showing with 13 additions and 14 deletions.
  1. +13 −14 src/core/Hash.pm6
@@ -515,21 +515,20 @@ my class Hash { # declared in BOOTSTRAP
)
}

method ASSIGN-KEY(::?CLASS:D: TKey \key, TValue \assignval) is raw {
my \storage := nqp::getattr(self, Map, '$!storage');
my str $which = nqp::unbox_s(key.WHICH);
method ASSIGN-KEY(::?CLASS:D: TKey \key, Mu \assignval) is raw {
my \storage := nqp::getattr(self, Map, '$!storage');
my \WHICH := key.WHICH;
my \existing := nqp::atkey(storage,WHICH);
nqp::if(
nqp::existskey(storage,$which),
(nqp::getattr(nqp::atkey(storage,$which),Pair,'$!value')
= assignval),
nqp::getattr(
(nqp::bindkey(storage,$which,
Pair.new(key,nqp::p6scalarfromdesc(
nqp::getattr(self,Hash,'$!descriptor')) = assignval)
)),
Pair,
'$!value'
)
nqp::isnull(existing),
nqp::stmts(
((my \scalar := nqp::p6scalarfromdesc( # assign before
nqp::getattr(self,Hash,'$!descriptor') # binding to get
)) = assignval), # type check
nqp::bindkey(storage,WHICH,Pair.new(key,scalar)),
scalar
),
(nqp::getattr(existing,Pair,'$!value') = assignval)
)
}

0 comments on commit f61ba41

Please sign in to comment.
You can’t perform that action at this time.