Skip to content

Commit

Permalink
Make Capture[n] (and thus $0, $1, ...) about 5x as fast
Browse files Browse the repository at this point in the history
By making the AT-POS candidates better inlineable by moving the
Failure creating code to a separate subroutine, thus allowing the
hotpath to be inlined.
  • Loading branch information
lizmat committed Jan 15, 2022
1 parent 7dc3add commit 11c8f82
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/core.c/Capture.pm6
Expand Up @@ -53,18 +53,20 @@ my class Capture { # declared in BOOTSTRAP
!! Nil
}

multi method AT-POS(Capture:D: Int:D \pos) is raw {
my int $pos = nqp::unbox_i(pos);
sub OUT_OF_RANGE(int $got) {
Failure.new(
X::OutOfRange.new(:what($*INDEX // 'Index'), :$got, :range<0..^Inf>)
)
}

multi method AT-POS(Capture:D: Int:D $pos) is raw {
nqp::islt_i($pos,0)
?? Failure.new(X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..^Inf>))
?? OUT_OF_RANGE($pos)
!! nqp::ifnull(nqp::atpos(@!list,$pos),Nil)
}
multi method AT-POS(Capture:D: \pos) is raw {
my int $pos = nqp::unbox_i(pos.Int);
multi method AT-POS(Capture:D: $pos) is raw {
nqp::islt_i($pos,0)
?? Failure.new(X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..^Inf>))
?? OUT_OF_RANGE($pos)
!! nqp::ifnull(nqp::atpos(@!list,$pos),Nil)
}

Expand Down

0 comments on commit 11c8f82

Please sign in to comment.