Skip to content

Commit

Permalink
Streamline Supply.words similar to Supply.lines
Browse files Browse the repository at this point in the history
- remove unused variables
- use nqp::substr() logic to its fullest
- don't keep nqp::chars value in variable

Didn't bother to look at any performance difference, don't expect much.
  • Loading branch information
lizmat committed Dec 31, 2019
1 parent c63d8a8 commit 779b0a2
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/core.c/Supply.pm6
Expand Up @@ -1092,40 +1092,30 @@ my class Supply does Awaitable {
method words(Supply:D $self:) {
supply {
my str $str;
my int $chars;
my int $left;
my int $pos;
my int $nextpos;
my int $found;
my int $cr;
my int $crlf;

whenever self -> \val {
$str = $str ~ nqp::unbox_s(val);
$chars = nqp::chars($str);
$pos = nqp::findnotcclass(
nqp::const::CCLASS_WHITESPACE, $str, 0, $chars);
whenever self -> str $val {
$str = nqp::concat($str,$val);
$pos = nqp::findnotcclass(
nqp::const::CCLASS_WHITESPACE,$str,0,nqp::chars($str));

while ($left = $chars - $pos) > 0 {
while ($left = nqp::chars($str) - $pos) > 0 {
$nextpos = nqp::findcclass(
nqp::const::CCLASS_WHITESPACE, $str, $pos, $left
);
nqp::const::CCLASS_WHITESPACE,$str,$pos,$left);

last unless $left = $chars - $nextpos; # broken word
last unless $left = nqp::chars($str) - $nextpos; # broken word

emit( nqp::box_s(
nqp::substr( $str, $pos, $nextpos - $pos ), Str)
);
emit nqp::p6box_s(nqp::substr($str,$pos,$nextpos - $pos));

$pos = nqp::findnotcclass(
nqp::const::CCLASS_WHITESPACE,$str,$nextpos,$left);
}
$str = $pos < $chars
?? nqp::substr($str,$pos)
!! '';
$str = nqp::substr($str,$pos);

LAST {
emit( nqp::box_s($str, Str) ) if $str;
emit nqp::p6box_s($str) if nqp::chars($str);
}
}
}
Expand Down

0 comments on commit 779b0a2

Please sign in to comment.