Skip to content

Commit

Permalink
Use a smarter semaphore in Supply.produce
Browse files Browse the repository at this point in the history
Since the produced values can never be an nqp::null, use nqp::null as a
semaphore to indicate the first value has not yet been seen.  Removes the
need for a boolean semaphore.
  • Loading branch information
lizmat committed May 1, 2020
1 parent 0aa8b2a commit 9cabea0
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/core.c/Supply-factories.pm6
Expand Up @@ -494,17 +494,11 @@

method produce(Supply:D: &with) {
supply {
my $first := True;
my $reduced := Nil;
my $reduced := nqp::null;
whenever self -> \value {
if $first {
$reduced := value;
$first := False;
}
else {
$reduced := with($reduced, value);
}
emit $reduced;
emit $reduced := nqp::isnull($reduced)
?? value
!! with($reduced, value);
}
}
}
Expand Down

0 comments on commit 9cabea0

Please sign in to comment.