Skip to content

Commit

Permalink
Re-imagine @A[*] to use new infrastructure (60% faster)
Browse files Browse the repository at this point in the history
This is on top of the 5x that was already achieved by optimizing
the @A[@i] candidates (which the @A[*] was calling internally).
So the whatever slice is now 8x as fast as before.
  • Loading branch information
lizmat committed Dec 24, 2020
1 parent 2c09f31 commit 74c267e
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/core.c/array_slice.pm6
Expand Up @@ -357,33 +357,32 @@ multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,Bool() :$v!,*%other) is ra
}

# @a[*]
multi sub postcircumfix:<[ ]>( \SELF, Whatever:D ) is raw {
SELF[^SELF.elems];
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, *%_) is raw {

# Get the dispatch index
my int $index;
if nqp::getattr(%_,Map,'$!storage') {
my $lookup := Rakudo::Internals.ADVERBS_TO_DISPATCH_INDEX(%_);
if nqp::istype($lookup,X::Adverb) {
$lookup.what = "whatever slice";
$lookup.source = try { SELF.VAR.name } // SELF.^name;
return Failure.new($lookup);
}

# Good to go!
$index = $lookup;
}

# Do the correct processing for given dispatch index
Rakudo::Internals.ACCESS-DISPATCH-CLASS($index)
.new(SELF).slice(Rakudo::Iterator.IntRange(0,SELF.end))
}
multi sub postcircumfix:<[ ]>( \SELF, Whatever:D, Mu \assignee ) is raw {
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, Bool() :$delete!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.elems, 'delete', $delete, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, Bool() :$exists!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.elems, 'exists', $exists, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, Bool() :$kv!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.elems, 'kv', $kv, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, Bool() :$p!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.elems, 'p', $p, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, Bool() :$k!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.elems, 'k', $k, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, Bool() :$v!, *%other) is raw {
SLICE_MORE_LIST( SELF, ^SELF.elems, 'v', $v, %other )
}

# @a[**]
multi sub postcircumfix:<[ ]>(\SELF, HyperWhatever:D $, *%adv) is raw {
Expand Down

0 comments on commit 74c267e

Please sign in to comment.