Skip to content
Permalink
Browse files

Fix Str.Lines/Words iterator's count-only

- doing a count-only should *not* affect the iterator status
- makes it also about 5% faster
- also fix typo in Lines iterator, which caused an extra infix:<,> call
  • Loading branch information...
lizmat committed Sep 7, 2018
1 parent 8905575 commit 86468e1eccce8c14d1e1eb7ba52b89214721076f
Showing with 12 additions and 8 deletions.
  1. +12 −8 src/core/Str.pm6
@@ -1337,11 +1337,13 @@ my class Str does Stringy { # declared in BOOTSTRAP
method count-only(--> Int:D) {
my int $left;
my int $seen;
my int $pos = $!pos;
my int $chars = $!chars;

while ($left = $!chars - $!pos) > 0 {
($!pos = nqp::findcclass(
nqp::const::CCLASS_NEWLINE, $!str, $!pos, $left) + 1),
($seen = $seen + 1)
while ($left = $chars - $pos) > 0 {
$pos = nqp::findcclass(
nqp::const::CCLASS_NEWLINE, $!str, $pos, $left) + 1;
$seen = $seen + 1;
}
$seen
}
@@ -2203,12 +2205,14 @@ my class Str does Stringy { # declared in BOOTSTRAP
my int $left;
my int $nextpos;
my int $seen;
my int $pos = $!pos;
my int $chars = $!chars;

while ($left = $!chars - $!pos) > 0 {
while ($left = $chars - $pos) > 0 {
$nextpos = nqp::findcclass(
nqp::const::CCLASS_WHITESPACE, $!str, $!pos, $left);
$!pos = nqp::findnotcclass( nqp::const::CCLASS_WHITESPACE,
$!str, $nextpos, $!chars - $nextpos);
nqp::const::CCLASS_WHITESPACE, $!str, $pos, $left);
$pos = nqp::findnotcclass( nqp::const::CCLASS_WHITESPACE,
$!str, $nextpos, $chars - $nextpos);
$seen = $seen + 1;
}
$seen

0 comments on commit 86468e1

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