Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Build and use the protoregex table in a much smarter way. Immediately…
… shaves 25% off NQP test suite run time.
  • Loading branch information
jnthn committed May 26, 2012
1 parent 382602b commit 0197389
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/QRegex/Cursor.nqp
Expand Up @@ -182,11 +182,8 @@ role NQPCursorRole {
my @fates := $nfa.states[0];
my $start := 1;
my $fate := 0;
my $prefix := $name ~ ':sym<';
my $prefixchars := nqp::chars($prefix);
for %protorx {
my $rxname := ~$_;
if nqp::substr($rxname, 0, $prefixchars) eq $prefix {
if nqp::existskey(%protorx, $name) {
for %protorx{$name} -> $rxname {
$fate := $fate + 1;
@fates[$fate] := $rxname;
$nfa.mergesubrule($start, 0, $fate, self, $rxname);
Expand All @@ -199,7 +196,12 @@ role NQPCursorRole {
my %protorx;
for self.HOW.methods(self) -> $meth {
my $methname := ~$meth;
%protorx{$methname} := $meth if nqp::index($methname, ':sym<') >0;
my $sympos := nqp::index($methname, ':sym<');
if $sympos > 0 {
my $prefix := nqp::substr($methname, 0, $sympos);
%protorx{$prefix} := [] unless nqp::existskey(%protorx, $prefix);
nqp::push(%protorx{$prefix}, $methname);
}
}
%protorx;
}
Expand Down
7 changes: 2 additions & 5 deletions src/QRegex/NFA.nqp
Expand Up @@ -198,12 +198,9 @@ class QRegex::NFA {
# of all of the possible rules.
my %protorx := $cursor.HOW.cache($cursor, "!protoregex_table", { $cursor."!protoregex_table"() });
my $nfa := QRegex::NFA.new;
my $prefix := $name ~ ':sym<';
my $prefixchars := nqp::chars($prefix);
my $gotmatch := 0;
for %protorx {
my $rxname := ~$_;
if nqp::substr($rxname, 0, $prefixchars) eq $prefix {
if nqp::existskey(%protorx, $name) {
for %protorx{$name} -> $rxname {
$nfa.addedge(1, 0, $EDGE_SUBRULE, $rxname);
$gotmatch := 1;
}
Expand Down

0 comments on commit 0197389

Please sign in to comment.