Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change all nqp::substr+eq to nqp::eqat
This results in a performance boost of about 0.4 to 0.6% accross stage
parse and stage optimize!! /o/
  • Loading branch information
FROGGS committed Sep 17, 2014
1 parent 8ae74d2 commit 680162b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
30 changes: 16 additions & 14 deletions src/Perl6/Actions.nqp
Expand Up @@ -21,7 +21,7 @@ role STDActions {
my int $tabstop := $*W.find_symbol(['$?TABSTOP']);
my int $checkidx := 0;
while $checkidx < $actualchars {
if nqp::substr($ws, $checkidx, 1) eq "\t" {
if nqp::eqat($ws, "\t", $checkidx) {
$indent := $indent - ($tabstop - 1);
}
$checkidx := $checkidx + 1;
Expand Down Expand Up @@ -1975,7 +1975,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
# If it's a stub, add it to the "must compose at some point" list,
# then just evaluate to the type object. Don't need to do any more
# just yet.
if nqp::substr($<blockoid><statementlist><statement>[0], 0, 3) eq '...' {
if nqp::eqat($<blockoid><statementlist><statement>[0], '...', 0) {
unless $*PKGDECL eq 'role' {
$*W.add_stub_to_check($*PACKAGE);
}
Expand Down Expand Up @@ -3679,7 +3679,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$/.CURSOR.panic('Cannot have more than one sub-signature for a parameter');
}
%*PARAM_INFO<sub_signature_params> := $<signature>.ast;
if nqp::substr(~$/, 0, 1) eq '[' {
if nqp::eqat(~$/, '[', 0) {
%*PARAM_INFO<sigil> := '@';
%*PARAM_INFO<nominal_type> := $*W.find_symbol(['Positional']);
}
Expand Down Expand Up @@ -3809,9 +3809,10 @@ class Perl6::Actions is HLL::Actions does STDActions {

method type_constraint($/) {
if $<typename> {
if nqp::substr(~$<typename>, 0, 2) eq '::' && nqp::substr(~$<typename>, 2, 1) ne '?' {
my str $typename := ~$<typename>;
if nqp::eqat($typename, '::', 0) && !nqp::eqat($typename, '?', 2) {
# Set up signature so it will find the typename.
my $desigilname := nqp::substr(~$<typename>, 2);
my $desigilname := nqp::substr($typename, 2);
unless %*PARAM_INFO<type_captures> {
%*PARAM_INFO<type_captures> := []
}
Expand Down Expand Up @@ -3897,7 +3898,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$/.CURSOR.panic('Cannot have more than one sub-signature for a parameter');
}
%*PARAM_INFO<sub_signature_params> := $<signature>.ast;
if nqp::substr(~$/, 0, 1) eq '[' {
if nqp::eqat(~$/, '[', 0) {
%*PARAM_INFO<sigil> := '@' unless %*PARAM_INFO<sigil>;
}
}
Expand Down Expand Up @@ -4401,7 +4402,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
# Add & to name.
my @name := nqp::clone($*longname.components());
my $final := @name[+@name - 1];
if nqp::substr($final, 0, 1) ne '&' {
unless nqp::eqat($final, '&', 0) {
@name[+@name - 1] := '&' ~ $final;
}
my $macro := find_macro_routine(@name);
Expand Down Expand Up @@ -4766,7 +4767,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$is_hash := 1;
}
elsif $elem ~~ QAST::Var
&& nqp::substr($elem.name, 0, 1) eq '%' {
&& nqp::eqat($elem.name, '%', 0) {
# first item is a hash
$is_hash := 1;
}
Expand Down Expand Up @@ -4868,7 +4869,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
make make_dot_equals($/[0].ast, $/[1].ast);
return 1;
}
elsif $past && nqp::substr($past.name, 0, 19) eq '&METAOP_TEST_ASSIGN' {
elsif $past && nqp::eqat($past.name, '&METAOP_TEST_ASSIGN', 0) {
$past.push($/[0].ast);
$past.push(block_closure(make_thunk_ref($/[1].ast, $/)));
make $past;
Expand Down Expand Up @@ -5735,7 +5736,8 @@ class Perl6::Actions is HLL::Actions does STDActions {
# dispatch with. Note that for '::T' style things we need to make a
# GenericHOW, though whether/how it's used depends on context.
if $<longname> {
if nqp::substr(~$<longname>, 0, 2) ne '::' {
my str $str_longname := ~$<longname>;
if !nqp::eqat($str_longname, '::', 0) {
my $longname := $*W.dissect_longname($<longname>);
my $type := $*W.find_symbol($longname.type_name_parts('type name'));
if $<arglist> {
Expand All @@ -5751,10 +5753,10 @@ class Perl6::Actions is HLL::Actions does STDActions {
if $<arglist> || $<typename> {
$/.CURSOR.panic("Cannot put type parameters on a type capture");
}
if ~$<longname> eq '::' {
if $str_longname eq '::' {
$/.CURSOR.panic("Cannot use :: as a type name");
}
make $*W.pkg_create_mo($/, %*HOW<generic>, :name(nqp::substr(~$<longname>, 2)));
make $*W.pkg_create_mo($/, %*HOW<generic>, :name(nqp::substr($str_longname, 2)));
}
}
else {
Expand Down Expand Up @@ -7108,11 +7110,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
nqp::die("You gave us an exponent for the magnitude, but you forgot the base.")
if !nqp::defined($base) && nqp::defined($exponent);

if nqp::substr($number, 0, 1) eq '-' {
if nqp::eqat($number, '-', 0) {
$sign := -1;
$number := nqp::substr($number, 1);
}
if nqp::substr($number, 0, 1) eq '0' {
if nqp::eqat($number, '0', 0) {
my $radix_name := nqp::uc(nqp::substr($number, 1, 1));
if nqp::index('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', $radix_name) > $radix {
$number := nqp::substr($number, 2);
Expand Down
8 changes: 4 additions & 4 deletions src/Perl6/Grammar.nqp
Expand Up @@ -3002,7 +3002,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $pos;
{ $*longname := $*W.dissect_longname($<longname>); $pos := $/.CURSOR.pos }
[
|| <?{ nqp::substr($<longname>.Str, 0, 2) eq '::' || $*W.is_name($*longname.components()) }>
|| <?{ nqp::eqat($<longname>.Str, '::', 0) || $*W.is_name($*longname.components()) }>
<.unsp>?
[
<?{ $*W.is_type($*longname.components()) }>
Expand All @@ -3025,7 +3025,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
unless $ok {
my $trap := %deftrap{$name};
$/.CURSOR.worry("Use of non-subscript <...> where postfix is expected; please use whitespace")
if $trap && nqp::substr($/.CURSOR.orig, $/.CURSOR.pos, 1) eq '<';
if $trap && nqp::eqat($/.CURSOR.orig, '<', $/.CURSOR.pos);
if $trap == 1 { # probably misused P5ism
$<longname>.CURSOR.sorryobs("bare '$name'", ".$name if you meant \$_, or use an explicit invocant or argument");
}
Expand Down Expand Up @@ -3155,7 +3155,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
| <longname>
<?{
my $longname := $*W.dissect_longname($<longname>);
nqp::substr(~$<longname>, 0, 2) eq '::' ??
nqp::eqat(~$<longname>, '::', 0) ??
1 !! # ::T introduces a type, so always is one
$*W.is_name($longname.type_name_parts('type name'))
}>
Expand Down Expand Up @@ -4011,7 +4011,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
next if $*W.is_lexically_visible('&' ~ $name, %sym<lex>);

# no sigil or &
if $name ge 'a' || nqp::substr($name,0,1) eq '&' {
if nqp::eqat($name, '&', 0) || $name ge 'a' {
%unk_routines{$name} := [] unless %unk_routines{$name};
my @suggs := $*W.suggest_routines($name);
%routine_suggestion{$name} := @suggs;
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Metamodel/RoleToClassApplier.nqp
Expand Up @@ -36,7 +36,7 @@ my class RoleToClassApplier {
sub has_public_attribute($target, $name) {
my @attributes := $target.HOW.attributes($target, :local(1));
for @attributes {
return 1 if nqp::substr($_.name, 2) eq $name && $_.has_accessor;
return 1 if nqp::eqat($_.name, $name, 2) && $_.has_accessor;
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/ModuleLoader.nqp
Expand Up @@ -295,7 +295,7 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
# appropriately copied.
if $orig.HOW.name($orig) eq 'Stash' {
for $orig.FLATTENABLE_HASH() {
if !nqp::existskey($current, $_.key) || nqp::substr($_.key, 0, 1) eq '&' {
if !nqp::existskey($current, $_.key) || nqp::eqat($_.key, '&', 0) {
$current{$_.key} := $_.value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Optimizer.nqp
Expand Up @@ -1057,7 +1057,7 @@ class Perl6::Optimizer {
my $last_stmt := get_last_stmt($value);
if nqp::istype($last_stmt, QAST::Op) {
my str $op := $last_stmt.op;
if $op eq 'p6bool' || nqp::substr($op, nqp::chars($op) - 1, 1) eq 'I' {
if $op eq 'p6bool' || nqp::eqat($op, 'I', -1) {
return $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Pod.nqp
Expand Up @@ -101,7 +101,7 @@ class Perl6::Pod {
} else {
# and this is the worst hack of them all.
# Hide your kids, hide your wife!
my $truth := nqp::substr($colonpair, 1, 1) ne '!';
my $truth := !nqp::eqat($colonpair, '!', 1);

$val := $*W.add_constant('Int', 'int', $truth).compile_time_value;
}
Expand Down
11 changes: 5 additions & 6 deletions src/Perl6/World.nqp
Expand Up @@ -116,8 +116,7 @@ sub levenshtein($a, $b) {

# switching two letters costs only 1 instead of 2.
if $apos + 1 <= $alen && $bpos + 1 <= $blen &&
nqp::substr($a, $apos + 1, 1) eq $bchar &&
nqp::substr($b, $bpos + 1, 1) eq $achar {
nqp::eqat($a, $bchar, $apos + 1) && nqp::eqat($b, $achar, $bpos + 1) {
my $cd := levenshtein_impl($apos+2, $bpos+2, $estimate+1) + 1;
$distance := $cd if $cd < $distance;
}
Expand Down Expand Up @@ -657,7 +656,7 @@ class Perl6::World is HLL::World {
}

# Creates a new container descriptor and adds it to the SC.
method create_container_descriptor($of, $rw, $name, $default = $of, $dynamic = nqp::chars($name) > 2 && nqp::substr($name, 1, 1) eq "*") {
method create_container_descriptor($of, $rw, $name, $default = $of, $dynamic = nqp::chars($name) > 2 && nqp::eqat($name, '*', 1)) {
my $cd_type := self.find_symbol(['ContainerDescriptor']);
my $cd := $cd_type.new( :$of, :$rw, :$name, :$default, :$dynamic );
self.add_object($cd);
Expand Down Expand Up @@ -2465,15 +2464,15 @@ class Perl6::World is HLL::World {
}

method suggest_routines($name) {
my $with_sigil := nqp::substr($name, 0, 1) eq "&";
$name := "&" ~ $name unless $with_sigil;
my $with_sigil := nqp::eqat($name, '&', 0);
$name := '&' ~ $name unless $with_sigil;
my @suggestions;
my @candidates := [[], [], []];
my &inner-evaluator := make_levenshtein_evaluator($name, @candidates);
my %seen;
%seen{$name} := 1;
sub evaluate($name, $value, $hash) {
return 1 unless nqp::substr($name, 0, 1) eq "&";
return 1 unless nqp::eqat($name, '&', 0);
return 1 if nqp::existskey(%seen, $name);

%seen{$name} := 1;
Expand Down

0 comments on commit 680162b

Please sign in to comment.