Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
do sawcaps opt by making CAPS more representative
  • Loading branch information
TimToady committed Apr 8, 2015
1 parent 1fd8cde commit a997d3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/QRegex/Cursor.nqp
Expand Up @@ -837,7 +837,7 @@ class NQPCursor does NQPCursorRole {
my $NO_CAPS := nqp::hash();
method MATCH() {
my $match := nqp::getattr(self, NQPCursor, '$!match');
unless nqp::istype($match, NQPMatch) || nqp::ishash($match) {
if nqp::isnull($match) || (!nqp::istype($match, NQPMatch) && !nqp::ishash($match)) {
# Set up basic state of Match.
my $list;
my $hash := nqp::hash();
Expand All @@ -851,7 +851,6 @@ class NQPCursor does NQPCursorRole {
# For captures with lists, initialize the lists.
my %caplist := $NO_CAPS;
my $rxsub := nqp::getattr(self, NQPCursor, '$!regexsub');
my int $sawcaps := 1;
if !nqp::isnull($rxsub) && nqp::defined($rxsub) {
%caplist := nqp::can($rxsub, 'CAPS') ?? $rxsub.CAPS() !! nqp::null();
if !nqp::isnull(%caplist) && nqp::istrue(%caplist) {
Expand All @@ -865,18 +864,20 @@ class NQPCursor does NQPCursorRole {
nqp::defor($list, $list := nqp::list()),
$name, nqp::list())
!! nqp::bindkey($hash, $name, nqp::list());
$sawcaps := 1;
}
elsif nqp::iterval($curcap) >= 1 {
$sawcaps := 1;
}
}
}
}

# Walk the Cursor stack and populate the Cursor.
my $cs := nqp::getattr(self, NQPCursor, '$!cstack');
if $sawcaps && !nqp::isnull($cs) && nqp::istrue($cs) {
# Dunno why this optimization gives a NullPointer exception on JVM...
#?if jvm
if !nqp::isnull($cs) && nqp::istrue($cs) {
#?endif
#?if !jvm
if %caplist && !nqp::isnull($cs) && nqp::istrue($cs) {
#?endif
my int $cselems := nqp::elems($cs);
my int $csi;
while $csi < $cselems {
Expand Down
4 changes: 1 addition & 3 deletions src/QRegex/P6Regex/Actions.nqp
Expand Up @@ -835,9 +835,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
$count := %astcap{''};
}
}
%capnames{''} := $count;
nqp::deletekey(%capnames, '$!from');
nqp::deletekey(%capnames, '$!to');
%capnames{''} := $count; # will be deleted in SET_CAPS
%capnames;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/NQPRoutine.nqp
Expand Up @@ -372,7 +372,7 @@ my knowhow NQPRegex {
method SET_CAPS($caps) {
my %h_caps;
for $caps {
%h_caps{$_.key} := $_.value;
%h_caps{$_.key} := $_.value unless $_.key eq '';
}
$!caps := %h_caps;
}
Expand Down

0 comments on commit a997d3d

Please sign in to comment.