Skip to content

Commit 116ef73

Browse files
committed
Always produce integers in captures hash
So we don't have to coerce things during comparison.
1 parent 8c8d0a8 commit 116ef73

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/QRegex/P5Regex/Actions.nqp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,13 @@ class QRegex::P5Regex::Actions is HLL::Actions {
392392
$block;
393393
}
394394

395-
sub capnames($ast, $count) {
395+
sub capnames($ast, int $count) {
396396
my %capnames;
397397
my $rxtype := $ast.rxtype;
398398
if $rxtype eq 'concat' {
399399
for $ast.list {
400400
my %x := capnames($_, $count);
401-
for %x { %capnames{$_.key} := +%capnames{$_.key} + $_.value; }
401+
for %x { %capnames{$_.key} := nqp::add_i((%capnames{$_.key} // 0), $_.value); }
402402
$count := %x{''};
403403
}
404404
}
@@ -407,7 +407,7 @@ class QRegex::P5Regex::Actions is HLL::Actions {
407407
for $ast.list {
408408
my %x := capnames($_, $count);
409409
for %x {
410-
%capnames{$_.key} := +%capnames{$_.key} < 2 && %x{$_.key} == 1 ?? 1 !! 2;
410+
%capnames{$_.key} := (%capnames{$_.key} // 0) < 2 && %x{$_.key} == 1 ?? 1 !! 2;
411411
}
412412
$count := %x{''};
413413
}
@@ -435,7 +435,7 @@ class QRegex::P5Regex::Actions is HLL::Actions {
435435
%capnames{$_} := 1;
436436
}
437437
my %x := capnames($ast[0], $count);
438-
for %x { %capnames{$_.key} := +%capnames{$_.key} + %x{$_.key} }
438+
for %x { %capnames{$_.key} := nqp::add_i((%capnames{$_.key} // 0), %x{$_.key}) }
439439
$count := %x{''};
440440
}
441441
elsif $rxtype eq 'quant' {

src/QRegex/P6Regex/Actions.nqp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -894,16 +894,18 @@ class QRegex::P6Regex::Actions is HLL::Actions {
894894
if $rxtype eq 'concat' || $rxtype eq 'goal' || $rxtype eq 'conjseq' {
895895
for $ast.list {
896896
my %x := capnames($_, $count);
897-
for %x { %capnames{$_.key} := +%capnames{$_.key} + $_.value; }
897+
for %x {
898+
%capnames{$_.key} := nqp::add_i((%capnames{$_.key} // 0), $_.value);
899+
}
898900
$count := %x{''};
899901
}
900902
}
901903
elsif $rxtype eq 'altseq' || $rxtype eq 'alt' {
902-
my $max := $count;
904+
my int $max := $count;
903905
for $ast.list {
904906
my %x := capnames($_, $count);
905907
for %x {
906-
%capnames{$_.key} := +%capnames{$_.key} < 2 && %x{$_.key} == 1 ?? 1 !! 2;
908+
%capnames{$_.key} := (%capnames{$_.key} // 0) < 2 && %x{$_.key} == 1 ?? 1 !! 2;
907909
}
908910
$max := %x{''} if %x{''} > $max;
909911
}
@@ -914,7 +916,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
914916
if $name eq '' { $name := $count; $ast.name($name); }
915917
my @names := nqp::split('=', $name);
916918
for @names {
917-
my $n := nqp::radix(10, $_, 0, 0)[0];
919+
my int $n := nqp::radix(10, $_, 0, 0)[0];
918920
if $_ eq '0' || $n > 0 {
919921
$count := $n + 1;
920922
%capnames{$n} := 1
@@ -936,7 +938,7 @@ class QRegex::P6Regex::Actions is HLL::Actions {
936938
}
937939
}
938940
my %x := capnames($ast[0], $count);
939-
for %x { %capnames{$_.key} := +%capnames{$_.key} + %x{$_.key} }
941+
for %x { %capnames{$_.key} := nqp::add_i((%capnames{$_.key} // 0), %x{$_.key}) }
940942
$count := %x{''};
941943
}
942944
elsif $rxtype eq 'quant' || $rxtype eq 'dynquant' {

0 commit comments

Comments
 (0)