Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor words to not use comb/matches.
In theory this should be a load faster. Instead it's twice as slow
on pick-words. Maybe repeated utf-8 scanning kills it.
  • Loading branch information
jnthn committed Sep 19, 2012
1 parent 0973612 commit f843f61
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/Str.pm
Expand Up @@ -736,8 +736,21 @@ my class Str does Stringy {
nqp::islt_i($pos, $left) ?? '' !! nqp::p6box_s(nqp::substr($str, $left, $pos + 1 - $left));
}

method words(Str:D: $limit = *) {
self.comb( / \S+ /, $limit );
method words(Str:D: $limit = $Inf) {
my $taken = 0;
my str $str = nqp::unbox_s(self);
my int $eos = nqp::chars($str);
my int $pos = 0;
gather while $taken < $limit {
my int $start = nqp::findnotcclass(
pir::const::CCLASS_WHITESPACE, $str, $pos, $eos);
last if $start == $eos;
my int $end = pir::find_cclass__Iisii(
pir::const::CCLASS_WHITESPACE, $str, $start, $eos);
take nqp::p6box_s(nqp::substr($str, $start, $end - $start));
$pos = $end;
$taken++;
}
}

method encode(Str:D $encoding = 'utf8') {
Expand Down

0 comments on commit f843f61

Please sign in to comment.