Skip to content

Commit 041e1e2

Browse files
committed
knock a few % off stage parse
1) Avoid creating Match objects we'll just throw away. 2) Avoid traversing the cstack when we know nothing is wanted from it.
1 parent 35c589e commit 041e1e2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/QRegex/Cursor.nqp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ class NQPCursor does NQPCursorRole {
851851
# For captures with lists, initialize the lists.
852852
my %caplist := $NO_CAPS;
853853
my $rxsub := nqp::getattr(self, NQPCursor, '$!regexsub');
854+
my int $sawcaps := 0;
854855
if !nqp::isnull($rxsub) && nqp::defined($rxsub) {
855856
%caplist := nqp::can($rxsub, 'CAPS') ?? $rxsub.CAPS() !! nqp::null();
856857
if !nqp::isnull(%caplist) && nqp::istrue(%caplist) {
@@ -864,22 +865,26 @@ class NQPCursor does NQPCursorRole {
864865
nqp::defor($list, $list := nqp::list()),
865866
$name, nqp::list())
866867
!! nqp::bindkey($hash, $name, nqp::list());
868+
$sawcaps := 1;
869+
}
870+
elsif nqp::iterval($curcap) >= 1 {
871+
$sawcaps := 1;
867872
}
868873
}
869874
}
870875
}
871876

872877
# Walk the Cursor stack and populate the Cursor.
873878
my $cs := nqp::getattr(self, NQPCursor, '$!cstack');
874-
if !nqp::isnull($cs) && nqp::istrue($cs) {
879+
if $sawcaps && !nqp::isnull($cs) && nqp::istrue($cs) {
875880
my int $cselems := nqp::elems($cs);
876881
my int $csi;
877882
while $csi < $cselems {
878883
my $subcur := nqp::atpos($cs, $csi);
879-
my $submatch := $subcur.MATCH;
880884
my $name := nqp::getattr($subcur, $?CLASS, '$!name');
881-
if !nqp::isnull($name) && nqp::defined($name) {
882-
if $name ne '' && nqp::ordat($name, 0) == 36 && ($name eq '$!from' || $name eq '$!to') {
885+
if !nqp::isnull($name) && nqp::defined($name) && $name ne '' {
886+
my $submatch := $subcur.MATCH();
887+
if nqp::ordat($name, 0) == 36 && ($name eq '$!from' || $name eq '$!to') {
883888
nqp::bindattr_i($match, NQPMatch, $name, $submatch.from);
884889
}
885890
elsif nqp::index($name, '=') < 0 {

0 commit comments

Comments
 (0)