Skip to content

Commit

Permalink
Make a lot of integers native in NQP code
Browse files Browse the repository at this point in the history
They're about 4x as fast in NQP for loops and so on.  Probably also
should do this for all the places where integer values are used as
flags.
  • Loading branch information
lizmat committed Nov 27, 2020
1 parent 45246ae commit 6852f40
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Perl6/Actions.nqp
Expand Up @@ -6712,7 +6712,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
my $semis := $<semilist><statement>;
my $numsemis := nqp::elems($semis);

my $i := -1;
my int $i := -1;
while ++$i < $numsemis {
my $EXPR := $semis[$i]<EXPR>;
if nqp::defined($EXPR) {
Expand All @@ -6726,7 +6726,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$past.push(QAST::Op.new( :op('call'), :name('&infix:<,>'), :node($/)));
}

my $semi := -1;
my int $semi := -1;
while ++$semi < $numsemis {
my $EXPR := @EXPR[$semi];
if $EXPR<colonpair> { # might start with a colonpair
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/C3MRO.nqp
Expand Up @@ -143,7 +143,7 @@ role Perl6::Metamodel::C3MRO {
}

# Otherwise, remove what was accepted from the merge lists.
my $i := -1;
my int $i := -1;
while ++$i < nqp::elems(@merge_list) {
my @new_list;
for @merge_list[$i] {
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/Dispatchers.nqp
Expand Up @@ -143,7 +143,7 @@ class Perl6::Metamodel::WrapDispatcher is Perl6::Metamodel::BaseDispatcher {

method remove($wrapper) {
my @cands := self.candidates;
my $i := -1;
my int $i := -1;
while ++$i < +@cands {
if nqp::decont(@cands[$i]) =:= nqp::decont($wrapper) {
nqp::splice(@cands, [], $i, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/Perl6/Metamodel/Finalization.nqp
Expand Up @@ -4,7 +4,7 @@ role Perl6::Metamodel::Finalization {
method setup_finalization($obj) {
my @mro := self.mro($obj);
my int $i := -1;
my $ocount := nqp::elems(@mro);
my int $ocount := nqp::elems(@mro);
my @destroyers;
while ++$i < $ocount {
my $class := @mro[$i];
Expand All @@ -18,8 +18,8 @@ role Perl6::Metamodel::Finalization {
&& nqp::can($classHOW, 'roles')
{
my @ins_roles := $classHOW.ins_roles($class, :with-submethods-only);
my $j := -1;
my $rcount := nqp::elems(@ins_roles);
my int $j := -1;
my int $rcount := nqp::elems(@ins_roles);
while ++$j < $rcount {
my $r := @ins_roles[$j];
my $submeth := nqp::atkey(@ins_roles[$j].HOW.submethod_table(@ins_roles[$j]), 'DESTROY');
Expand Down
42 changes: 21 additions & 21 deletions src/Perl6/Pod.nqp
Expand Up @@ -284,9 +284,9 @@ class Perl6::Pod {
}

for $<pod_content> {
my $array := $_.ast;
my $elems := $array.elems;
my $i := -1;
my $array := $_.ast;
my int $elems := $array.elems;
my int $i := -1;
while ++$i < $elems {
@children.push($array.AT-POS($i));
}
Expand Down Expand Up @@ -1215,11 +1215,11 @@ class Perl6::Pod {
# header and multi-line content.
#
# Tricky, isn't it? Let's try to handle it sanely.
my $sepnum := 0;
my $firstsepindex := 0;
my $differentseps := 0;
my $firstsep;
my $i := -1;
my int $sepnum := 0;
my int $firstsepindex := 0;
my int $differentseps := 0;
my int $i := -1;
while ++$i < +@rows {
unless nqp::islist(@rows[$i]) {
$sepnum := $sepnum + 1;
Expand Down Expand Up @@ -1267,7 +1267,7 @@ class Perl6::Pod {
else {
# multi-line header, one-lined rows
my @hlines := [];
my $i := -1;
my int $i := -1;
while ++$i < $firstsepindex {
@hlines.push(@rows.shift);
}
Expand All @@ -1278,7 +1278,7 @@ class Perl6::Pod {
}
else {
my @hlines := [];
my $i := -1;
my int $i := -1;
if $differentseps {
while ++$i < $firstsepindex {
@hlines.push(@rows.shift);
Expand Down Expand Up @@ -1376,12 +1376,12 @@ class Perl6::Pod {
sub normalize_vis_col_sep_rows(@Rows) {
# leading and trailing column separators are handled and warned about
my @rows := @Rows;
my $nlp := 0; # number of leading pipes
my $ntp := 0; # number of trailing pipes
my $nr := 0; # number of data rows
my $leading := 0;
my $trailing := 0;
my $i := -1;
my int $nlp := 0; # number of leading pipes
my int $ntp := 0; # number of trailing pipes
my int $nr := 0; # number of data rows
my int $leading := 0;
my int $trailing := 0;
my int $i := -1;
while ++$i < +@rows {
unless @rows[$i] ~~ $is_row_sep {
++$nr;
Expand Down Expand Up @@ -1414,7 +1414,7 @@ class Perl6::Pod {

sub remove_border_pipes(@Rows, $leading, $trailing) {
my @rows := @Rows;
my $i := -1; # BUG: nqp did NOT warn about missing $i
my int $i := -1; # BUG: nqp did NOT warn about missing $i
while ++$i < +@rows {
unless @rows[$i] ~~ $is_row_sep {
if $leading || $trailing {
Expand Down Expand Up @@ -1451,7 +1451,7 @@ class Perl6::Pod {
}
}

my $i := -1;
my int $i := -1;
while ++$i < +@rows {
unless @rows[$i] ~~ /^\s*$/ {
if $w != -1 {
Expand All @@ -1468,7 +1468,7 @@ class Perl6::Pod {
# split the vis col sep rows between cells
# note we don't merge multiple rows yet
my @res;
my $i := 0;
my int $i := 0;
for @rows -> $row {
if $row ~~ $is_row_sep {
@res.push($row);
Expand Down Expand Up @@ -1504,7 +1504,7 @@ class Perl6::Pod {

sub merge_rows(@rows) {
my @result := @rows[0];
my $i := 1;
my int $i := 1;
while $i < +@rows {
my $j := -1;
while ++$j < +@rows[$i] {
Expand All @@ -1531,11 +1531,11 @@ class Perl6::Pod {
# unset - maybe

# collect cell delimiters per row
my $i := -1;
my int $i := -1;
while ++$i < +@rows {
unless @rows[$i] ~~ $is_row_sep {
my @line := nqp::split('', @rows[$i]);
my $j := -1;
my int $j := -1;
while ++$j < +@line {
unless @suspects[$j] {
if @line[$j] ne ' ' {
Expand Down

0 comments on commit 6852f40

Please sign in to comment.