Skip to content

Commit 5e9403a

Browse files
committed
Convert substr+eq to eqat
nqp::eqat is much faster than doing a substr+eq.
1 parent 9099516 commit 5e9403a

File tree

11 files changed

+26
-19
lines changed

11 files changed

+26
-19
lines changed

src/HLL/CommandLine.nqp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ class HLL::CommandLine::Parser {
171171

172172
method is-option($x) {
173173
return 0 if $x eq '-' || $x eq '--';
174-
return 1 if nqp::substr($x, 0, 1) eq '-';
175-
0;
174+
nqp::eqat($x, '-', 0);
176175
}
177176

178177
method wants-value($x) {
179178
my $spec := %!options{$x};
180-
nqp::substr($spec, 0, 1) eq 's';
179+
nqp::eqat($spec, 's', 0);
181180
}
182181

183182
method optional-value($x) {
@@ -215,7 +214,7 @@ class HLL::CommandLine::Parser {
215214
while $i < $arg-count {
216215
my $cur := @args[$i];
217216
if self.is-option($cur) {
218-
if nqp::substr($cur, 0, 2) eq '--' {
217+
if nqp::eqat($cur, '--', 0) {
219218
# long option
220219
my $opt := nqp::substr(@args[$i], 2);
221220
my $idx := nqp::index($opt, '=');

src/HLL/Compiler.nqp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class HLL::Compiler does HLL::Backend::Default {
105105
if self.input-incomplete($output) {
106106
# Need to get more code before we execute
107107
# Strip the trailing \, but reinstate the newline
108-
if nqp::substr($code, 0, nqp::chars($code) - 2) eq "\\\n" {
108+
if nqp::eqat($code, "\\\n", 0) {
109109
$code := nqp::substr($code, 0, nqp::chars($code) - 2) ~ "\n";
110110
}
111111
if $code {
@@ -153,7 +153,7 @@ class HLL::Compiler does HLL::Backend::Default {
153153
method eval($code, *@args, *%adverbs) {
154154
my $output;
155155

156-
if $code && nqp::substr($code, nqp::chars($code) - 2) eq "\\\n" {
156+
if $code && nqp::eqat($code, "\\\n", nqp::chars($code) - 2) {
157157
return self.needs-more-input();
158158
}
159159

@@ -650,7 +650,7 @@ class HLL::Compiler does HLL::Backend::Default {
650650
# Treat \r\n as a single logical newline. Note that NFG
651651
# implementations, we should check it really is a lone \r,
652652
# not the first bit of a \r\n grapheme.
653-
if nqp::iseq_i($ord, 13) && nqp::substr($s, $jpos - 1, 1) eq "\r" &&
653+
if nqp::iseq_i($ord, 13) && nqp::eqat($s, "\r", $jpos - 1) &&
654654
$jpos < $eos && nqp::iseq_i(nqp::ord($s, $jpos), 10)
655655
{
656656
$jpos := nqp::add_i($jpos, 1);

src/HLL/Grammar.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ position C<pos>.
273273

274274
# see if the opening bracket is repeated
275275
my int $len := 1;
276-
while nqp::substr($target, ++$pos, 1) eq $start {
276+
while nqp::eqat($target, $start, ++$pos) {
277277
$len++;
278278
}
279279
if $len > 1 {

src/HLL/sprintf.nqp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ my module sprintf {
237237
sub normalize($float) {
238238
my @parts := nqp::split('e', nqp::lc($float));
239239
my $sign := '';
240-
if nqp::substr(@parts[0],0,1) eq '-' {
240+
if nqp::eqat(@parts[0], '-', 0) {
241241
$sign := '-';
242242
@parts[0] := nqp::substr(@parts[0], 1);
243243
}
@@ -271,7 +271,7 @@ my module sprintf {
271271

272272
my $zeroes := infix_x("0", 1 + ($precision > $d ?? $precision - $d !! 0));
273273

274-
$lhs_s := nqp::substr($lhs_s, 1) if nqp::substr($lhs_s, 0, 1) eq '-';
274+
$lhs_s := nqp::substr($lhs_s, 1) if nqp::eqat($lhs_s, '-', 0);
275275
my $lhs_I := nqp::fromstr_I($lhs_s, $knowhow);
276276
my $rhs_I := nqp::fromstr_I("1" ~ $rhs_s ~ $zeroes, $knowhow); # The leading 1 is to preserve leading zeroes
277277
my $cc := nqp::chars(nqp::tostr_I($rhs_I));

src/NQP/Actions.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ class NQP::Actions is HLL::Actions {
14941494
$ast[$i] := $ast[$i][0];
14951495
$ast[$i].flat(1);
14961496
$ast[$i].named(1) if nqp::istype($ast[$i], QAST::Var)
1497-
&& nqp::substr($ast[$i].name, 0, 1) eq '%';
1497+
&& nqp::eqat($ast[$i].name, '%', 0);
14981498
}
14991499
$i++;
15001500
}

src/NQP/Optimizer.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class NQP::Optimizer {
137137
self.visit_children($block);
138138

139139
# Methods with late-bound names poison lowering.
140-
if nqp::substr($block.name, 0, 12) eq '!!LATENAME!!' {
140+
if nqp::eqat($block.name, '!!LATENAME!!', 0) {
141141
self.poison_lowering();
142142
}
143143

src/QRegex/Cursor.nqp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,16 @@ role NQPMatchRole is export {
854854
my int $litlen := nqp::chars($str);
855855
my str $target := nqp::getattr_s($!shared, ParseShared, '$!target');
856856
if $litlen < 1 ||
857+
#?if jvm
857858
($i ?? nqp::lc(nqp::substr($target, $!pos, $litlen)) eq nqp::lc($str)
858-
!! nqp::substr($target, $!pos, $litlen) eq $str) {
859+
#?endif
860+
#?if js
861+
($i ?? nqp::lc(nqp::substr($target, $!pos, $litlen)) eq nqp::lc($str)
862+
#?endif
863+
#?if moar
864+
($i ?? nqp::eqatic($target, $str, $!pos)
865+
#?endif
866+
!! nqp::eqat($target, $str, $!pos)) {
859867
my $cur := self."!cursor_start_cur"();
860868
$cur."!cursor_pass"($!pos + $litlen);
861869
$cur
@@ -1300,7 +1308,7 @@ class NQPMatch is NQPCapture does NQPMatchRole {
13001308
else {
13011309
my int $len := nqp::chars($_);
13021310
$maxlen := $len if $len > $maxlen && $pos + $len <= $eos
1303-
&& nqp::substr($tgt, $pos, $len) eq $_;
1311+
&& nqp::eqat($tgt, $_, $pos);
13041312
}
13051313
last if $s && $maxlen > -1;
13061314
}

src/how/NQPClassHOW.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ knowhow NQPClassHOW {
782782
}
783783
}
784784
method should_trace($obj, $name) {
785-
return 0 if nqp::substr($name, 0, 1) eq '!';
785+
return 0 if nqp::eqat($name, '!', 0);
786786
for @!trace_exclude {
787787
return 0 if $name eq $_;
788788
}

src/how/NQPParametricRoleHOW.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ knowhow NQPParametricRoleHOW {
143143
my $meth := nqp::can(nqp::iterval($_), 'instantiate_generic')
144144
?? nqp::iterval($_).instantiate_generic($pad)
145145
!! nqp::iterval($_).clone();
146-
if nqp::substr($name, 0, 12) eq '!!LATENAME!!' {
146+
if nqp::eqat($name, '!!LATENAME!!', 0) {
147147
$name := nqp::atkey($pad, nqp::substr($name, 12));
148148
$meth.'!set_name'($name);
149149
}

src/vm/moar/HLL/Backend.nqp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class HLL::Backend::MoarVM {
8585
}
8686
nqp::sayfh(nqp::getstderr(), "Writing profiler output to $filename");
8787
my $profile_fh := open($filename, :w);
88-
my $want_json := nqp::substr($filename, -5) eq '.json';
89-
my $want_sql := nqp::substr($filename, -4) eq '.sql';
88+
my $want_json := nqp::eqat($filename, '.json', -5);
89+
my $want_sql := nqp::eqat($filename, '.sql', -4);
9090

9191
my $escaped_backslash;
9292
my $escaped_dquote;

0 commit comments

Comments
 (0)