Skip to content

Commit

Permalink
Make Str.chop(N) about 5x as fast
Browse files Browse the repository at this point in the history
First check for bigint ness, then use native int logic only
  • Loading branch information
lizmat committed Sep 5, 2018
1 parent ae739ad commit 07089e8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/Str.pm6
Expand Up @@ -130,8 +130,10 @@ my class Str does Stringy { # declared in BOOTSTRAP
)
}
multi method chop(Str:D: Int() $chopping) {
my Int $chars = nqp::chars($!value) - $chopping;
$chars > 0 ?? nqp::p6box_s(nqp::substr($!value,0,$chars)) !! '';
nqp::isbig_I(nqp::decont($chopping))
|| (my int $chars = nqp::sub_i(nqp::chars($!value),$chopping)) <= 0
?? ''
!! nqp::p6box_s(nqp::substr($!value,0,$chars))
}

# TODO Use coercer in 1 candidate when RT131014
Expand Down

0 comments on commit 07089e8

Please sign in to comment.