Skip to content

Commit

Permalink
Remove unnecessary caching on .elems
Browse files Browse the repository at this point in the history
Only a Seq needs caching of .elems nowadays, and it does so internally.

Makes @A[*-1] another 10% or so faster and probably has speed advantages
in other situations as well.
  • Loading branch information
lizmat committed Dec 19, 2016
1 parent b39c0d8 commit ab26b58
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/core/Block.pm
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ my class Block { # declared in BOOTSTRAP
(my $n := nqp::getattr(
nqp::getattr($self,Code,'$!signature'),Signature,'$!count')
),Num) && nqp::isnanorinf($n)) || nqp::iseq_i(nqp::unbox_i($n),1),
$self(nqp::if(nqp::isconcrete(list),list.cache.elems,0)),
$self(|(nqp::if(nqp::isconcrete(list),list.cache.elems,0) xx $n))
$self(nqp::if(nqp::isconcrete(list),list.elems,0)),
$self(|(nqp::if(nqp::isconcrete(list),list.elems,0) xx $n))
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Buf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ multi sub pack(@template, *@items) {
my $data = shift @items // Buf.new;
$data.=encode if nqp::istype($data,Str);
if $amount eq '*' {
$amount = $data.cache.elems;
$amount = $data.elems;
}
if $amount eq '' {
$amount = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/core/WhateverCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ my class WhateverCode is Code {
Signature,
'$!count'
),1),
$self(nqp::if(nqp::isconcrete(list),list.cache.elems,0)),
$self(|(nqp::if(nqp::isconcrete(list),list.cache.elems,0)
$self(nqp::if(nqp::isconcrete(list),list.elems,0)),
$self(|(nqp::if(nqp::isconcrete(list),list.elems,0)
xx nqp::getattr(
nqp::getattr($self,Code,'$!signature'),
Signature,
Expand Down
34 changes: 17 additions & 17 deletions src/core/array_slice.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ multi sub POSITIONS(
Callable :$eagerize = -> $idx {
nqp::if(
nqp::istype($idx,Whatever),
nqp::if(nqp::isconcrete(SELF),SELF.cache.elems,0),
nqp::if(nqp::isconcrete(SELF),SELF.elems,0),
SELF.EXISTS-POS($idx)
)
}
Expand Down Expand Up @@ -398,33 +398,33 @@ multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,:$v!,*%other) is raw {

# @a[*]
multi sub postcircumfix:<[ ]>( \SELF, Whatever:D ) is raw {
SELF[^SELF.cache.elems];
SELF[^SELF.elems];
}
multi sub postcircumfix:<[ ]>( \SELF, Whatever:D, Mu \assignee ) is raw {
SELF[^SELF.cache.elems] = assignee;
SELF[^SELF.elems] = assignee;
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$BIND!) is raw {
X::Bind::Slice.new(type => SELF.WHAT).throw;
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$delete!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'delete', $delete, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'delete', $delete, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$exists!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'exists', $exists, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'exists', $exists, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$kv!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'kv', $kv, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'kv', $kv, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$p!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'p', $p, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'p', $p, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$k!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'k', $k, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'k', $k, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$v!, *%other) is raw {
nqp::elems(nqp::getattr(%other,Map,'$!storage'))
?? SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'v', $v, %other )
!! SELF[^SELF.cache.elems];
?? SLICE_MORE_LIST( SELF, ^SELF.elems, 'v', $v, %other )
!! SELF[^SELF.elems];
}

# @a[**]
Expand All @@ -440,24 +440,24 @@ multi sub postcircumfix:<[ ]>(\SELF, :$BIND!) is raw {
X::Bind::ZenSlice.new(type => SELF.WHAT).throw;
}
multi sub postcircumfix:<[ ]>(\SELF, :$delete!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'delete', $delete, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'delete', $delete, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$exists!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'exists', $exists, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'exists', $exists, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$kv!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'kv', $kv, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'kv', $kv, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$p!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'p', $p, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'p', $p, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$k!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'k', $k, %other );
SLICE_MORE_LIST( SELF, ^SELF.elems, 'k', $k, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$v!, *%other) is raw {
nqp::elems(nqp::getattr(%other,Map,'$!storage'))
?? SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'v', $v, %other )
!! SELF[^SELF.cache.elems];
?? SLICE_MORE_LIST( SELF, ^SELF.elems, 'v', $v, %other )
!! SELF[^SELF.elems];
}
multi sub postcircumfix:<[ ]>(\SELF, *%other) is raw {
SELF.ZEN-POS(|%other);
Expand Down
8 changes: 4 additions & 4 deletions src/core/multidim_slice.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ sub MD-ARRAY-SLICE-ONE-POSITION(\SELF, \indices, \idx, int $dim, \target) is raw
MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS(idx), indices, indices.AT-POS($next-dim), $next-dim, target)
}
elsif nqp::istype(idx, Whatever) {
for ^SELF.cache.elems {
for ^SELF.elems {
MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS($_), indices, indices.AT-POS($next-dim), $next-dim, target)
}
}
elsif nqp::istype(idx, Callable) {
MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, idx.(|(SELF.cache.elems xx (idx.count == Inf ?? 1 !! idx.count))), $dim, target);
MD-ARRAY-SLICE-ONE-POSITION(SELF, indices, idx.(|(SELF.elems xx (idx.count == Inf ?? 1 !! idx.count))), $dim, target);
}
else {
MD-ARRAY-SLICE-ONE-POSITION(SELF.AT-POS(idx.Int), indices, indices.AT-POS($next-dim), $next-dim, target)
Expand All @@ -34,12 +34,12 @@ sub MD-ARRAY-SLICE-ONE-POSITION(\SELF, \indices, \idx, int $dim, \target) is raw
nqp::push(target, SELF.AT-POS(idx))
}
elsif nqp::istype(idx, Whatever) {
for ^SELF.cache.elems {
for ^SELF.elems {
nqp::push(target, SELF.AT-POS($_))
}
}
elsif nqp::istype(idx, Callable) {
nqp::push(target, SELF.AT-POS(idx.(|(SELF.cache.elems xx (idx.count == Inf ?? 1 !! idx.count)))))
nqp::push(target, SELF.AT-POS(idx.(|(SELF.elems xx (idx.count == Inf ?? 1 !! idx.count)))))
}
else {
nqp::push(target, SELF.AT-POS(idx.Int))
Expand Down

0 comments on commit ab26b58

Please sign in to comment.