Skip to content

Commit

Permalink
Make @A[*-1] candidates about 60% faster
Browse files Browse the repository at this point in the history
By saving 1 Scalar allocation per call.
  • Loading branch information
lizmat committed Dec 12, 2020
1 parent 79b55ac commit 2d5d3bf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/core.c/array_slice.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, Bool() :$v!, *%other) is r

# @a[->{}]
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block ) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! SELF[$pos]
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, Mu \assignee ) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! (SELF[$pos] = assignee)
Expand All @@ -318,47 +318,47 @@ multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$BIND!) is raw {
X::Bind::Slice.new(type => SELF.WHAT).throw;
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$delete!,*%other) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'delete', $delete, %other)
!! SLICE_MORE_LIST(SELF, @$pos, 'delete', $delete, %other)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$exists!,*%other) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'exists', $exists, %other)
!! SLICE_MORE_LIST(SELF, @$pos, 'exists', $exists, %other)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$kv!,*%other) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'kv', $kv, %other)
!! SLICE_MORE_LIST(SELF, @$pos, 'kv', $kv, %other)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$p!,*%other) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'p', $p, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'p', $p, %other )
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$k!,*%other) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'k', $k, %other)
!! SLICE_MORE_LIST(SELF, @$pos, 'k', $k, %other)
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$v!,*%other) is raw {
my $*INDEX = 'Effective index';
my $*INDEX := 'Effective index';
nqp::istype((my $pos := $block.POSITIONS(SELF)),Failure)
?? $pos
!! nqp::istype($pos,Int)
Expand Down

0 comments on commit 2d5d3bf

Please sign in to comment.