Closed tcbrindle closed 1 year ago
Patch coverage: 100.00%
and project coverage change: -0.01%
:warning:
Comparison is base (
16cd229
) 97.58% compared to head (5e4c62e
) 97.58%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This might be a bit controversial...
The
filter
,drop
anddrop_while
adaptors, when operating on multipass sequences, cache the first cursor: that is, the first call tofirst()
does a (potentially)O(N)
pass over the data, but subsequent calls tofirst()
returns the cached cursor. I originally did this for the same reason that Ranges does it: I wantedfirst()
to always be (amortised?)O(1)
.As time goes on though, I'm less certain that this was the right choice. We definitely need
is_last()
to beO(1)
; I'm very sure we also wantlast()
to beO(1)
for bounded sequences. But I'm less convinced aboutfirst()
. After all, getting the second element withinc()
can never be constant-time, so why do we special-case getting the first one?Various later Flux adaptors don't do caching where the Ranges versions do, and there seems to be little ill effect. Also, the internal iteration implementation of
filter
has never used the cache, and I don't think anyone has ever noticed.Getting rid of caching allows const-iteration, which is useful for such fundamental adaptors, and stops people needing to reach for
mut_ref
. It also makes life easier for the optimiser.