Skip to content

Commit 17382e6

Browse files
committed
Optimize cursor_push_cstack a bit
- don't use temporary variables we don't need - don't use if ! { } else { } but if { } else { } and change the blocks around - don't box native strings
1 parent a3bf109 commit 17382e6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/QRegex/Cursor.nqp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -552,23 +552,25 @@ role NQPMatchRole is export {
552552
nqp::push($!cstack, $capture);
553553
}
554554
elsif !nqp::isnull($capture) {
555-
my $name := nqp::getattr_s($capture, $?CLASS, '$!name');
556-
if !nqp::isnull_s($name) && nqp::defined($name) {
557-
nqp::push($!cstack, $capture);
558-
}
559-
else { # is top capture anonymous enough to be reused?
560-
my $top := nqp::atpos($!cstack,-1);
561-
my str $topname := nqp::getattr_s($top, $?CLASS, '$!name');
562-
if !nqp::isnull_s($topname) && nqp::defined($topname) {
563-
nqp::push($!cstack, $capture);
555+
if nqp::isnull_s(nqp::getattr_s($capture, $?CLASS, '$!name')) {
556+
if nqp::isnull_s(nqp::getattr_s(nqp::atpos($!cstack,-1), $?CLASS, '$!name')) {
557+
# $top anon capture just used for pos advancement, so update
558+
# it in place. We replace the whole capture because jvm
559+
# can't seem to copy only the pos, and because the chances
560+
# are that both captures are in the nursury anyway.
561+
nqp::bindpos($!cstack, -1, $capture);
564562
}
563+
564+
# top capture anonymous enough to be reused
565565
else {
566-
# $top anon capture just used for pos advancement, so update it in place.
567-
# We replace the whole capture because jvm can't seem to copy only the pos,
568-
# and because the chances are that both captures are in the nursury anyway.
569-
nqp::bindpos($!cstack, -1, $capture);
566+
nqp::push($!cstack, $capture);
570567
}
571568
}
569+
570+
# capture has a name
571+
else {
572+
nqp::push($!cstack, $capture);
573+
}
572574
}
573575
$!cstack;
574576
}

0 commit comments

Comments
 (0)