Skip to content

Commit

Permalink
Make Supply.squish a multi
Browse files Browse the repository at this point in the history
With some optimizations, specifically for the default &with
  • Loading branch information
lizmat committed Jan 18, 2020
1 parent 4079702 commit 7925bfd
Showing 1 changed file with 64 additions and 20 deletions.
84 changes: 64 additions & 20 deletions src/core.c/Supply-coercers.pm6
Expand Up @@ -197,31 +197,75 @@
}
}

method squish(Supply:D: :&as, :&with is copy) {
&with //= &[===];
multi method squish(Supply:D:) {
supply {
my int $first = 1;
my Mu $last;
my Mu $target;

if &as {
whenever self -> \val {
$target = &as(val);
if $first || !&with($last,$target) {
$first = 0;
emit(val);
}
$last = $target;
my $last;
my $which;
whenever self -> \val {
if $first {
emit val;
$first = 0;
$last := val.WHICH;
}
elsif $last ne ($which := val.WHICH) {
emit val;
$last := $which;
}
}
else {
whenever self -> \val {
if $first || !&with($last, val) {
$first = 0;
emit(val);
}
$last = val;
}
}
multi method squish(Supply:D: :&as!, :&with!) {
supply {
my int $first = 1;
my $target;
my $last;
whenever self -> \val {
$target := as(val);
if $first {
emit val;
$first = 0;
}
else {
emit val unless with($last, $target);
}
$last := $target;
}
}
}
multi method squish(Supply:D: :&as!) {
supply {
my int $first = 1;
my $target;
my $last;
my $which;
whenever self -> \val {
$target := as(val);
if $first {
emit val;
$first = 0;
$last := $target.WHICH;
}
elsif $last ne ($which := $target.WHICH) {
emit val;
$last := $which;
}
}
}
}
multi method squish(Supply:D: :&with!) {
supply {
my int $first = 1;
my $last;
whenever self -> \val {
if $first {
emit val;
$first = 0;
}
elsif nqp::not_i(with($last, val)) {
emit val;
}
$last := val;
}
}
}
Expand Down

0 comments on commit 7925bfd

Please sign in to comment.