So-o. Zoffix insists that everything is correct here, and perhaps it is so.
That being said, I don't quite understand why it can't be done. Maybe somebody
else can take a look also. Here's my logic:

So if you have

@array[0...@array.end]

and

@array[0..*]

Would we get identical results from both of these snippets? I guess we should.
But if it is so, why can't it just pretend that * is @array.end? If I
understand correctly, the range object is right there for inspection, so
everything should be possible.

Zoffix++ pointed out ( https://irclog.perlgeek.de/perl6/2017-10-08#i_15273200 )
that 0..* will stop at the first hole, but there's a ticket for that:
https://rt.perl.org/Ticket/Display.html?id=127573

So assuming that the bug is eventually resolved and both @array[0...@array.end]
and @array[0..*] start giving exactly the same result in all cases, why can't
it be done? And if these two snippets give different results, then what are
these difference? This would be some good doc material.

If there's a chance that it can be done, let's keep this open. The difference
is dramatic and [0..*] is very common in normal code.

On 2017-10-07 21:44:40, c...@zoffix.com wrote:
> On Sat, 06 Jun 2015 20:24:32 -0700, r...@hoelz.ro wrote:
> > Let's say I have an array where @array.end == $end. Using
> > @array[0..$end] is about 20 times faster than @array[0..*]. I have
> > attached an example script that demonstrates this.
>
>
> Thanks for the report, however there's no issue with the compiler
> here.
>
> You're comparing different behaviours: 0..* is a lazy Iterable, so
> extra checks
> are performed to stop iteration of indices once an end is reached. If
> you make 0..$end lazy,
> so the same checks are performed, the perf difference actually gives
> 0..* is small edge (likely due
> to optimized Ranger.iterator)
>
> <Zoffix__> m: my @array = 1..1000; my $end = @array.end; for ^500 { $
> = @array[0..*] }; say now - INIT now
> <camelia> rakudo-moar 39d50a: OUTPUT: «3.050471␤»
> <Zoffix__> m: my @array = 1..1000; my $end = @array.end; for ^500 { $
> = @array[lazy 0..$end] }; say now - INIT now
> <camelia> rakudo-moar 39d50a: OUTPUT: «3.3454447␤»

Reply via email to