Skip to content

Commit

Permalink
Streamline Hash.AT-KEY, jnthn++ for the pointer
Browse files Browse the repository at this point in the history
With improved inlining we have now, it makes sense to take the capture
taking logic out of AT-KEY, so that it can be inlined for the most common
case.  Capture taking/$!whence setting is now done in a private method
!AT-KEY-WHENCE, which also takes care of the case where there was no
$!storage allocated yet.  Makes Hash.AT-KEY about 1.7x faster for the common
case of looking up an existing Str:D key.
  • Loading branch information
lizmat committed Dec 5, 2017
1 parent f6c2e70 commit 6601da5
Showing 1 changed file with 23 additions and 46 deletions.
69 changes: 23 additions & 46 deletions src/core/Hash.pm
Expand Up @@ -45,62 +45,39 @@ my class Hash { # declared in BOOTSTRAP
)
}

method !AT-KEY-WHENCE(Str:D \key) is raw {
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindkey(
nqp::if(
nqp::isconcrete(nqp::getattr(self,Map,'$!storage')),
nqp::getattr(self,Map,'$!storage'),
nqp::bindattr(self,Map,'$!storage',nqp::hash)
),key,v)
}
)
}

multi method AT-KEY(Hash:D: Str:D \key) is raw {
nqp::if(
nqp::getattr(self,Map,'$!storage').DEFINITE,
nqp::isconcrete(nqp::getattr(self,Map,'$!storage')),
nqp::ifnull(
nqp::atkey(nqp::getattr(self,Map,'$!storage'),
nqp::unbox_s(key)),
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindkey(nqp::getattr(self,Map,'$!storage'),
nqp::unbox_s(key),v) }
)
nqp::atkey(nqp::getattr(self,Map,'$!storage'),key),
self!AT-KEY-WHENCE(key)
),
nqp::p6bindattrinvres(
(my \vv := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindkey(
nqp::if(
nqp::getattr(self,Map,'$!storage').DEFINITE,
nqp::getattr(self,Map,'$!storage'),
nqp::bindattr(self,Map,'$!storage',nqp::hash)
),
nqp::unbox_s(key),vv)
}
)
self!AT-KEY-WHENCE(key)
)
}
multi method AT-KEY(Hash:D: \key) is raw {
nqp::if(
nqp::getattr(self,Map,'$!storage').DEFINITE,
nqp::isconcrete(nqp::getattr(self,Map,'$!storage')),
nqp::ifnull(
nqp::atkey(nqp::getattr(self,Map,'$!storage'),
nqp::unbox_s(key.Str)),
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindkey(nqp::getattr(self,Map,'$!storage'),
nqp::unbox_s(key.Str),v) }
)
nqp::atkey(nqp::getattr(self,Map,'$!storage'),key.Str),
self!AT-KEY-WHENCE(key.Str)
),
nqp::p6bindattrinvres(
(my \vv := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindkey(
nqp::if(
nqp::getattr(self,Map,'$!storage').DEFINITE,
nqp::getattr(self,Map,'$!storage'),
nqp::bindattr(self,Map,'$!storage',nqp::hash)
),
nqp::unbox_s(key.Str),vv)
}
)
self!AT-KEY-WHENCE(key.Str)
)
}

Expand Down

0 comments on commit 6601da5

Please sign in to comment.