Skip to content
Permalink
Browse files

Make for Str.lines { } about 2x as fast

- lose the return
- bind to the final result instead of copying the result
- lose a scope
  • Loading branch information...
lizmat committed Sep 4, 2018
1 parent b8f37bf commit 3dd09be33f95105455475e96e5f08f6002f1e4b4
Showing with 13 additions and 8 deletions.
  1. +13 −8 src/core/Str.pm6
@@ -1308,14 +1308,19 @@ my class Str does Stringy { # declared in BOOTSTRAP
}
method new(\string) { nqp::create(self)!SET-SELF(string) }
method pull-one() {
my int $left;
return IterationEnd if ($left = $!chars - $!pos) <= 0;

my int $nextpos = nqp::findcclass(
nqp::const::CCLASS_NEWLINE, $!str, $!pos, $left);
my str $found = nqp::substr($!str, $!pos, $nextpos - $!pos);
$!pos = $nextpos + 1;
$found;
nqp::if(
(my int $left = $!chars - $!pos) > 0,
nqp::stmts(
(my int $nextpos = nqp::findcclass(
nqp::const::CCLASS_NEWLINE, $!str, $!pos, $left)),
(my $found := nqp::p6box_s(
nqp::substr($!str, $!pos, $nextpos - $!pos)
)),
($!pos = $nextpos + 1),
$found
),
IterationEnd
)
}
method push-all($target --> IterationEnd) {
my int $left;

0 comments on commit 3dd09be

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