Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Speed up Str.trans a bit
Don't use the flexible, expensive CALLERS:: PseudoStash, but the
straight nqp equivalent (which is about 50x faster)
  • Loading branch information
lizmat committed Feb 16, 2016
1 parent ad63cd0 commit 204a03c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/core/Str.pm
Expand Up @@ -1433,7 +1433,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
submethod compare_substitution(
$substitution, int $pos, int $length --> Nil
) {
$/ := CALLERS::('$/');
$/ := nqp::getlexcaller('$/');
if $!next_match > $pos
|| $!next_match == $pos && $!substitution_length < $length {

Expand All @@ -1445,7 +1445,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

method !triage_substitution($_) {
$/ := CALLERS::('$/');
$/ := nqp::getlexcaller('$/');
my $key := .key;
if nqp::istype($key,Regex) {
if $!source.match($key, :continue($!index)) -> \m {
Expand Down Expand Up @@ -1473,7 +1473,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

method !increment_index($s --> Nil) {
$/ := CALLERS::('$/');
$/ := nqp::getlexcaller('$/');
if nqp::istype($s,Regex) {
substr($!source,$!index) ~~ $s;
$!last_match_obj = $/;
Expand All @@ -1485,10 +1485,11 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
}

# note: changes outer $/
method get_next_substitution_result {
my $result = $!complement ?? $!first_substitution.value !! $!next_substitution.value;
my $cds := CALLERS::('$/');
$/ := CALLERS::('$/');
my $cds := nqp::getlexcaller('$/');
$/ := nqp::getlexcaller('$/');
$cds = $!match_obj;
my $orig-result = $result = ($result ~~ Callable ?? $result() !! $result).Str;
$result = ''
Expand All @@ -1501,7 +1502,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

method next_substitution() {
$/ := CALLERS::('$/');
$/ := nqp::getlexcaller('$/');
$!next_match = $!source.chars;
$!first_substitution //= @!substitutions[0];

Expand Down Expand Up @@ -1545,7 +1546,8 @@ my class Str does Stringy { # declared in BOOTSTRAP
multi method trans(Str:D: Pair:D \what, *%n) {
my $from = what.key;
my $to = what.value;
$/ := CALLERS::('$/');
$/ := nqp::getlexcaller('$/');

return self.trans(|%n, (what,))
if !nqp::istype($from,Str) # from not a string
|| !$from.defined # or a type object
Expand Down Expand Up @@ -1646,7 +1648,7 @@ my class Str does Stringy { # declared in BOOTSTRAP
};
}

$/ := CALLERS::('$/');
$/ := nqp::getlexcaller('$/');
my $lsm = LSM.new(:source(self), :squash($s), :complement($c));
for @changes -> $p {
X::Str::Trans::InvalidArg.new(got => $p).throw
Expand Down

0 comments on commit 204a03c

Please sign in to comment.