Closed Philippe-Cholet closed 11 months ago
Maybe I should merge .map(...).fold(init, &mut f)
into a single .fold(init, |...| ...)
?!
EDIT: It would be 6% slower.
As mentionned in the too big message, the specialization test was previously added (by me). I'm unsure I can merge this myself though. I wanted a feedback first anyway, thanks for it. EDIT: I guess now I can since you "approved those changes".
Related to #755.
This is so much faster that I'm wandering if I'm missing something here!
I previously added the specialization test: https://github.com/rust-itertools/itertools/commit/a9aaeb4cbacee3f4e83df56b3bb45d35d9167fa9
I'm unsure we can fold the
while let
loop as we need to cloneiter
at every step of it. Both attempts below successfully pass the tests but are not faster.Maybe there is a solution involving
std::cell::???
but I'm not familiar enough with this, are you? I tried withitertools::rciter
but it was 60% slower (andRc
means theuse_alloc
feature). And with a basicRcIter::fold
specialization, I even had an (expected) error at runtime.I eventually found a way to rely on
iter.fold
usingunsafe
only (to hold&mut I
and&I
at the same time) but it's the same performance as the currentfold
specialization. I'm not familiar with unsafe Rust so it might just be dumb in the first place.