Skip to content

Commit

Permalink
Fast-path for integer case of Str.Numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jun 9, 2019
1 parent 5af9f97 commit b5c354d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/Str.pm6
Expand Up @@ -342,6 +342,12 @@ my class Str does Stringy { # declared in BOOTSTRAP
}

multi method Numeric(Str:D: --> Numeric:D) {
# Fast-path the integer case if there's no '.'.
unless self.contains('.') {
my \rr = nqp::radix_I(10, $!value, 0, 0b10, Int);
return nqp::atpos(rr, 0) if nqp::iseq_i(nqp::atpos(rr, 2), nqp::chars(self));
}

# Handle special empty string
self.trim eq ""
?? 0
Expand Down

0 comments on commit b5c354d

Please sign in to comment.