Skip to content

Commit

Permalink
Convert nqp::istrue into nqp::elems
Browse files Browse the repository at this point in the history
In the same vein as 7573562, `if %hash`
or `if @array` just ends up checking the number of elems in the hash or
array, so doing it manually in places that get called a lot skips a lot
of calls to MVM_coerce_istrue.
  • Loading branch information
MasterDuke17 committed Mar 21, 2020
1 parent 2618241 commit 6239081
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 25 deletions.
21 changes: 12 additions & 9 deletions src/HLL/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -756,16 +756,19 @@ class HLL::Compiler does HLL::Backend::Default {
method linefileof($target, int $pos, int :$cache = 0, int :$directives = 0) {
my int $line := nqp::atpos_i(self.line_and_column_of($target, $pos, :$cache), 0);
my str $file := '';
if $directives && (my @clds := @*comp_line_directives) {
if $directives {
my @clds := @*comp_line_directives;
my int $i := nqp::elems(@clds);
while $i > 0 {
$i := $i - 1;
last if $line > @clds[$i][0];
}
if $line > @clds[$i][0] {
my @directive := @clds[$i];
$line := $line - @directive[0] + @directive[1] - 1;
$file := @directive[2];
if $i {
while $i > 0 {
$i := $i - 1;
last if $line > @clds[$i][0];
}
if $line > @clds[$i][0] {
my @directive := @clds[$i];
$line := $line - @directive[0] + @directive[1] - 1;
$file := @directive[2];
}
}
}
[$line, $file];
Expand Down
14 changes: 7 additions & 7 deletions src/HLL/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ An operator precedence parser.
$pos := nqp::getattr_i($termcur, NQPMatch, '$!pos');
nqp::bindattr_i($here, NQPMatch, '$!pos', $pos);
if $pos < 0 {
$here.panic('Missing required term after infix') if @opstack;
$here.panic('Missing required term after infix') if nqp::elems(@opstack);
return $here;
}

Expand All @@ -419,7 +419,7 @@ An operator precedence parser.
@postfixish := nqp::atkey(%termOPER, 'postfixish');

unless nqp::isnull(@prefixish) || nqp::isnull(@postfixish) {
while @prefixish && @postfixish {
while nqp::elems(@prefixish) && nqp::elems(@postfixish) {
my %preO := @prefixish[0]<OPER><O>.made;
my %postO := @postfixish[nqp::elems(@postfixish)-1]<OPER><O>.made;
my $preprec := nqp::ifnull(nqp::atkey(%preO, 'sub'), nqp::ifnull(nqp::atkey(%preO, 'prec'), ''));
Expand All @@ -441,8 +441,8 @@ An operator precedence parser.
self.EXPR_nonassoc($here, ~@prefixish[0], ~@postfixish[0]);
}
}
nqp::push(@opstack, nqp::shift(@prefixish)) while @prefixish;
nqp::push(@opstack, nqp::pop(@postfixish)) while @postfixish;
nqp::push(@opstack, nqp::shift(@prefixish)) while nqp::elems(@prefixish);
nqp::push(@opstack, nqp::pop(@postfixish)) while nqp::elems(@postfixish);
}
nqp::deletekey($termish, 'prefixish');
nqp::deletekey($termish, 'postfixish');
Expand Down Expand Up @@ -484,8 +484,8 @@ An operator precedence parser.
last;
}

while @opstack {
my %opO := @opstack[+@opstack-1]<OPER><O>.made;
while nqp::elems(@opstack) {
my %opO := @opstack[nqp::elems(@opstack)-1]<OPER><O>.made;

$opprec := nqp::ifnull(nqp::atkey(%opO, 'sub'), nqp::atkey(%opO, 'prec'));
last unless $opprec gt $inprec;
Expand Down Expand Up @@ -529,7 +529,7 @@ An operator precedence parser.
return $here if $pos < 0;
}

self.EXPR_reduce(@termstack, @opstack) while @opstack;
self.EXPR_reduce(@termstack, @opstack) while nqp::elems(@opstack);

self.'!clone_match_at'(
nqp::pop(@termstack),
Expand Down
4 changes: 2 additions & 2 deletions src/QAST/Block.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class QAST::Block is QAST::Node does QAST::Children {
nqp::bindattr($node, QAST::Block, '@!children', @children);
nqp::bindattr_s($node, QAST::Block, '$!name', $name);
nqp::bindattr_s($node, QAST::Block, '$!blocktype', $blocktype);
$node.set(%options) if %options;
$node.set(%options) if nqp::isconcrete(%options) && nqp::elems(%options);
$node
}

Expand Down Expand Up @@ -60,7 +60,7 @@ class QAST::Block is QAST::Node does QAST::Children {
my %NOSYMS := nqp::hash();
method symbol(str $name, *%attrs) {
%!symbol := nqp::hash() if nqp::isnull(%!symbol);
if %attrs {
if nqp::isconcrete(%attrs) && nqp::elems(%attrs) {
my %syms := %!symbol{$name};
if nqp::ishash(%syms) && nqp::elems(%syms) {
for %attrs {
Expand Down
2 changes: 1 addition & 1 deletion src/QAST/Op.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class QAST::Op is QAST::Node does QAST::Children {
nqp::bindattr($node, QAST::Op, '@!children', @children);
nqp::bindattr_s($node, QAST::Op, '$!name', $name);
nqp::bindattr_s($node, QAST::Op, '$!op', $op);
$node.set(%options) if %options;
$node.set(%options) if nqp::isconcrete(%options) && nqp::elems(%options);
$node
}

Expand Down
2 changes: 1 addition & 1 deletion src/QAST/Var.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class QAST::Var is QAST::Node does QAST::Children {
nqp::bindattr_s($node, QAST::Var, '$!name', $name);
nqp::bindattr_s($node, QAST::Var, '$!scope', $scope);
nqp::bindattr_s($node, QAST::Var, '$!decl', $decl);
$node.set(%options) if %options;
$node.set(%options) if nqp::isconcrete(%options) && nqp::elems(%options);
$node
}

Expand Down
4 changes: 2 additions & 2 deletions src/QRegex/Cursor.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ role NQPMatchRole is export {
my @rxfate := $nfa.states[0];
my $cur;
my $rxname;
while @fates {
while nqp::elems(@fates) {
$rxname := nqp::atpos(@rxfate, nqp::pop_i(@fates));
# note("invoking $rxname");
$cur := self."$rxname"();
Expand Down Expand Up @@ -1113,7 +1113,7 @@ class NQPMatch is NQPCapture does NQPMatchRole {

# Walk the Cursor stack and populate the Cursor.
my $cs := nqp::getattr(self, NQPMatch, '$!cstack');
if nqp::isnull($cs) || !nqp::istrue($cs) {}
if nqp::isnull($cs) || !nqp::isconcrete($cs) || !nqp::elems($cs) {}
elsif $onlyname ne '' {
# If there's only one destination, avoid repeated hash lookups
my int $cselems := nqp::elems($cs);
Expand Down
4 changes: 2 additions & 2 deletions src/QRegex/NFA.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ class QRegex::NFA {
# my $indent := dentin();
# note("$indent mergesubstates start $start to $to fate $fate") if $nfadeb;
@!states[0][$fate] := $fate; # overridden by !protoregex_nfa
if @substates {
if nqp::istype(@substates, NQPArray) && nqp::elems(@substates) {
# create an empty end state for the subrule's NFA
my int $substart := self.addstate();
# Copy (yes, clone) @substates[1..*] into our states.
Expand All @@ -671,7 +671,7 @@ class QRegex::NFA {
@substates := nqp::clone(@substates);
nqp::shift(@substates);
nqp::push(@!states, nqp::clone(nqp::shift(@substates)))
while @substates;
while nqp::elems(@substates);
# Go through all of the newly added states, and
# apply $substart offset to target states
# adjust fate edges to be $fate
Expand Down
2 changes: 1 addition & 1 deletion src/vm/moar/QAST/QASTOperationsMAST.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class QAST::MASTOperations {
my $mapper;
if $hll {
my %ops := %hll_ops{$hll};
$mapper := %ops{$name} if %ops;
$mapper := %ops{$name} if nqp::isconcrete(%ops) && nqp::elems(%ops);
}
$mapper := %core_ops{$name} unless $mapper;
$mapper
Expand Down
Binary file modified src/vm/moar/stage0/NQPHLL.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/NQPP6QRegex.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QAST.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QASTNode.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/QRegex.moarvm
Binary file not shown.
Binary file modified src/vm/moar/stage0/nqp.moarvm
Binary file not shown.

0 comments on commit 6239081

Please sign in to comment.