Skip to content
Permalink
Browse files

Make Str.trim-trailing about 10-20% faster

Depending on string and amount of whitespace
  • Loading branch information...
lizmat committed Jan 19, 2019
1 parent 99d30be commit 304feae9f09025297dbee2bdcb4e8ba877d30889
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/core/Str.pm6
@@ -2174,11 +2174,13 @@ my class Str does Stringy { # declared in BOOTSTRAP

method trim-trailing(Str:D: --> Str:D) {
my str $str = nqp::unbox_s(self);
my int $pos = nqp::chars($str) - 1;
$pos = $pos - 1
while nqp::isge_i($pos, 0)
&& nqp::iscclass(nqp::const::CCLASS_WHITESPACE, $str, $pos);
nqp::islt_i($pos, 0) ?? '' !! nqp::p6box_s(nqp::substr($str, 0, $pos + 1));
my int $pos = nqp::chars($str);
nqp::while(
nqp::isge_i(--$pos, 0)
&& nqp::iscclass(nqp::const::CCLASS_WHITESPACE, $str, $pos),
nqp::null
);
nqp::box_s(nqp::substr($str, 0, $pos + 1), Str)
}

method trim(Str:D: --> Str:D) {

0 comments on commit 304feae

Please sign in to comment.
You can’t perform that action at this time.