Skip to content

Commit 5034588

Browse files
committed
twiddle NQPCursor.MATCH a bit:
most of the times we don't actually have positionals, so keep a shared empty list. almost all of the keys start with non-$, so quick-check for that. iscclass is probably faster than the eq checks were, so do it first
1 parent c11b5e7 commit 5034588

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/QRegex/Cursor.nqp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,11 @@ class NQPMatch is NQPCapture {
744744
}
745745

746746
class NQPCursor does NQPCursorRole {
747+
my @EMPTY_LIST := [];
747748
method MATCH() {
748749
my $match := nqp::getattr(self, NQPCursor, '$!match');
749750
unless nqp::istype($match, NQPMatch) || nqp::ishash($match) {
750-
my $list := nqp::list();
751+
my $list;
751752
my $hash := nqp::hash();
752753
$match := nqp::create(NQPMatch);
753754
nqp::bindattr(self, NQPCursor, '$!match', $match);
@@ -762,19 +763,18 @@ class NQPCursor does NQPCursorRole {
762763
while $iter {
763764
$curcap := nqp::shift($iter);
764765
$key := nqp::iterkey_s($curcap);
765-
if $key eq '$!from' || $key eq '$!to' {
766-
nqp::bindattr_i($match, NQPMatch, $key, nqp::iterval($curcap).from);
767-
}
768-
elsif nqp::iscclass(nqp::const::CCLASS_NUMERIC, $key, 0) {
766+
if nqp::iscclass(nqp::const::CCLASS_NUMERIC, $key, 0) {
769767
$list := nqp::list() unless $list;
770768
nqp::bindpos($list, $key, nqp::iterval($curcap));
771769
}
770+
elsif $key && nqp::ordat($key, 0) == 36 && ($key eq '$!from' || $key eq '$!to') {
771+
nqp::bindattr_i($match, NQPMatch, $key, nqp::iterval($curcap).from);
772+
}
772773
else {
773-
$hash := nqp::hash() unless $hash;
774774
nqp::bindkey($hash, $key, nqp::iterval($curcap));
775775
}
776776
}
777-
nqp::bindattr($match, NQPCapture, '@!array', $list);
777+
nqp::bindattr($match, NQPCapture, '@!array', nqp::ifnull($list, @EMPTY_LIST));
778778
nqp::bindattr($match, NQPCapture, '%!hash', $hash);
779779
}
780780
$match

0 commit comments

Comments
 (0)