Skip to content
Permalink
Browse files

Make Str.chop(N) about 5x as fast

First check for bigint ness, then use native int logic only
  • Loading branch information...
lizmat committed Sep 5, 2018
1 parent ae739ad commit 07089e89e8b59bfebc2169d13816dab7e1913ece
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/core/Str.pm6
@@ -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

0 comments on commit 07089e8

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