Skip to content

Commit

Permalink
Streamline infix:<x>
Browse files Browse the repository at this point in the history
- add Bool:D candidate, makes it about 2x faster for True
- only call nqp::x if there's actually something to do, mild improvement

Inspired by https://twitter.com/zoffix/status/950537151212675072
  • Loading branch information
lizmat committed Jan 9, 2018
1 parent 5a76b3c commit f99943d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/Str.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2809,13 +2809,14 @@ multi sub infix:<~>(Str:D \a, Any:D \b) {
}
multi sub infix:<~>(*@args) { @args.join }

multi sub infix:<x>(Str:D $s, Bool:D $repetition --> Str:D) {
nqp::if($repetition, $s, '')
}
multi sub infix:<x>(Str:D $s, Int:D $repetition --> Str:D) {
nqp::if(nqp::islt_i($repetition, 0),
'',
nqp::p6box_s(nqp::x(nqp::unbox_s($s), nqp::unbox_i($repetition))))
nqp::if(nqp::islt_i($repetition, 1), '', nqp::x($s, $repetition))
}
multi sub infix:<x>(str $s, int $repetition --> str) {
nqp::if(nqp::islt_i($repetition, 0), '', nqp::x($s, $repetition))
nqp::if(nqp::islt_i($repetition, 1), '', nqp::x($s, $repetition))
}

multi sub infix:<cmp>(Str:D \a, Str:D \b --> Order:D) {
Expand Down

0 comments on commit f99943d

Please sign in to comment.