Skip to content

Commit

Permalink
Make the adverbless zen-slice (@A[]) a few percent faster
Browse files Browse the repository at this point in the history
By making it inline because it no longer needs to take a closure
  • Loading branch information
lizmat committed Jan 13, 2022
1 parent 8ac55c5 commit 21829c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/core.c/Rakudo/Internals/PostcircumfixAdverbs.pm6
Expand Up @@ -444,11 +444,11 @@ augment class Rakudo::Internals {
).new(SELF).slice($positions.iterator)
}

method SLICE_WHATEVER_WITH_ADVERBS(\SELF, %nameds) {
method SLICE_WITH_ADVERBS(\SELF, str $what, %nameds) {
nqp::istype(
(my $lookup := self.ADVERBS_TO_DISPATCH_INDEX(%nameds)),
X::Adverb
) ?? self.FAIL_X_ADVERB($lookup, 'whatever slice', SELF)
) ?? self.FAIL_X_ADVERB($lookup, $what, SELF)
!! self.ACCESS-SLICE-DISPATCH-CLASS(
$lookup
).new(SELF).slice(Rakudo::Iterator.IntRange(0,SELF.end))
Expand Down
24 changes: 5 additions & 19 deletions src/core.c/array_slice.pm6
Expand Up @@ -255,7 +255,7 @@ multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, *%_) is raw {
nqp::if(
nqp::isconcrete(my $storage := nqp::getattr(%_,Map,'$!storage'))
&& nqp::elems($storage),
Rakudo::Internals.SLICE_WHATEVER_WITH_ADVERBS(SELF, %_),
Rakudo::Internals.SLICE_WITH_ADVERBS(SELF, 'whatever slice', %_),
nqp::stmts( # fast path
SELF.iterator.push-all(my $buffer := nqp::create(IterationBuffer)),
$buffer.List
Expand All @@ -279,24 +279,10 @@ multi sub postcircumfix:<[ ]>(\SELF, HyperWhatever:D $, Mu \assignee) is raw {

# @a[]
multi sub postcircumfix:<[ ]>(\SELF, *%_) is raw {

# There are adverbs to check
if nqp::getattr(%_,Map,'$!storage') {
my $lookup := Rakudo::Internals.ADVERBS_TO_DISPATCH_INDEX(%_);
if nqp::istype($lookup,X::Adverb) {
$lookup.what = "zen slice";
$lookup.source = try { SELF.VAR.name } // SELF.^name;
return Failure.new($lookup);
}
Rakudo::Internals.ACCESS-SLICE-DISPATCH-CLASS(
$lookup
).new(SELF).slice(Rakudo::Iterator.IntRange(0,SELF.end))
}

# Just the thing, please
else {
SELF<>
}
nqp::isconcrete(my $storage := nqp::getattr(%_,Map,'$!storage'))
&& nqp::elems($storage)
?? Rakudo::Internals.SLICE_WITH_ADVERBS(SELF, 'zen slice', %_)
!! nqp::decont(SELF) # Just the thing, please
}
multi sub postcircumfix:<[ ]>(\SELF, :$BIND!) is raw {
X::Bind::ZenSlice.new(type => SELF.WHAT).throw;
Expand Down

0 comments on commit 21829c3

Please sign in to comment.