[swift-evolution] [Proposal] Fix lazy filter

Антон Жилин antonyzhilin at gmail.com
Sun Jun 19 11:56:14 CDT 2016


>
> It's not a bug.  Measuring the length of the source before allocating
> the destination array is usually a big win when compared to repeatedly
> growing the array's memory and copying all its elements.
> --
> -Dave


Usually yes, but not in the case of lazy filter. If predicate contains
anything more than a dozen CPU instructions, single-pass version is faster.

We often want the predicate to have side effects, but we cannot with
current implementation: the side effects will be doubled.

I also wonder if it's possible to allocate array with capacity of
underlying collection (before all lazy stuff) and shrink it in the end.

- Anton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160619/be0d403b/attachment.html>


More information about the swift-evolution mailing list