Skip to content

Commit 4f67a6c

Browse files
committed
Micro-optimize some commonly called methods
These are called a combined several million times when building Rakudo.
1 parent 1124404 commit 4f67a6c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/QRegex/Cursor.nqp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ role NQPCursorRole is export {
338338
my @fates := $nfa.run(nqp::getattr_s($shared, ParseShared, '$!target'), $!pos);
339339

340340
# Update highwater mark.
341-
my int $highwater := nqp::getattr_i($shared, ParseShared, '$!highwater');
342-
if $!pos > $highwater {
341+
if $!pos > nqp::getattr_i($shared, ParseShared, '$!highwater') {
343342
nqp::bindattr_i($shared, ParseShared, '$!highwater', $!pos);
344343
}
345344

@@ -389,9 +388,8 @@ role NQPCursorRole is export {
389388

390389
method !alt(int $pos, str $name, @labels = []) {
391390
# Update highwater mark.
392-
my $shared := $!shared;
393-
my int $highwater := nqp::getattr_i($shared, ParseShared, '$!highwater');
394-
if $pos > $highwater {
391+
my $shared := $!shared;
392+
if $pos > nqp::getattr_i($shared, ParseShared, '$!highwater') {
395393
nqp::bindattr_i($shared, ParseShared, '$!highwater', $pos);
396394
}
397395

@@ -946,7 +944,7 @@ class NQPCursor does NQPCursorRole {
946944
while $iter {
947945
my $curcap := nqp::shift($iter);
948946
my str $name := nqp::iterkey_s($curcap);
949-
$namecount++;
947+
++$namecount;
950948
if nqp::iterval($curcap) >= 2 {
951949
$onlyname := $name if $namecount == 1;
952950
nqp::ord($name) < 58
@@ -980,7 +978,7 @@ class NQPCursor does NQPCursorRole {
980978
my $submatch := $subcur.MATCH();
981979
nqp::push($dest, $submatch);
982980
}
983-
$csi++;
981+
++$csi;
984982
}
985983
}
986984
elsif !nqp::isnull(%caplist) && %caplist {
@@ -1026,7 +1024,7 @@ class NQPCursor does NQPCursorRole {
10261024
}
10271025
}
10281026
}
1029-
$csi++;
1027+
++$csi;
10301028
}
10311029
# {
10321030
# my $iter := nqp::iterator(%caplist);

0 commit comments

Comments
 (0)