Skip to content

Commit

Permalink
Streamline Array.Slip.AT-POS like Hash.AT-KEY
Browse files Browse the repository at this point in the history
- also use the same postfix for the private helper method
- WHENCE is an implementation detail, CONTAINER is what it gives
  • Loading branch information
lizmat committed Dec 5, 2017
1 parent 6601da5 commit fe8312b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
23 changes: 14 additions & 9 deletions src/core/Array.pm
Expand Up @@ -276,16 +276,21 @@ my class Array { # declared in BOOTSTRAP
method iterator() {
Rakudo::Iterator.ReifiedArray(self,$!descriptor)
}
multi method AT-POS(Int:D $pos) {

method !AT-POS-CONTAINER(Int:D \pos) {
nqp::p6bindattrinvres(
(my $scalar := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindpos(
nqp::getattr(self,List,'$!reified'),pos,$scalar) }
)
}

multi method AT-POS(Int:D \pos) {
nqp::ifnull(
nqp::atpos(nqp::getattr(self,List,'$!reified'),$pos),
nqp::p6bindattrinvres(
(my $scalar := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindpos(
nqp::getattr(self,List,'$!reified'),$pos,$scalar) }
)
nqp::atpos(nqp::getattr(self,List,'$!reified'),pos),
self!AT-POS-CONTAINER(pos)
)
}
method default() { $!descriptor.default }
Expand Down
10 changes: 5 additions & 5 deletions src/core/Hash.pm
Expand Up @@ -45,7 +45,7 @@ my class Hash { # declared in BOOTSTRAP
)
}

method !AT-KEY-WHENCE(Str:D \key) is raw {
method !AT-KEY-CONTAINER(Str:D \key) is raw {
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
Expand All @@ -65,19 +65,19 @@ my class Hash { # declared in BOOTSTRAP
nqp::isconcrete(nqp::getattr(self,Map,'$!storage')),
nqp::ifnull(
nqp::atkey(nqp::getattr(self,Map,'$!storage'),key),
self!AT-KEY-WHENCE(key)
self!AT-KEY-CONTAINER(key)
),
self!AT-KEY-WHENCE(key)
self!AT-KEY-CONTAINER(key)
)
}
multi method AT-KEY(Hash:D: \key) is raw {
nqp::if(
nqp::isconcrete(nqp::getattr(self,Map,'$!storage')),
nqp::ifnull(
nqp::atkey(nqp::getattr(self,Map,'$!storage'),key.Str),
self!AT-KEY-WHENCE(key.Str)
self!AT-KEY-CONTAINER(key.Str)
),
self!AT-KEY-WHENCE(key.Str)
self!AT-KEY-CONTAINER(key.Str)
)
}

Expand Down

0 comments on commit fe8312b

Please sign in to comment.