[swift-evolution] Adding a new filter method which returns 2 arrays

davesweeris at mac.com davesweeris at mac.com
Fri Jan 15 16:37:02 CST 2016

> On Jan 15, 2016, at 11:49, Arman Shan <armanshan12 at gmail.com> wrote:
> I definitely agree that this function should not replace the current filter function. We can give it a new name like "partition" or something.
+1 on “partition”. That makes the semantics much clearer, IMHO.

> Regarding the memory constraint: since both filter and partition methods will be provided, the developer may choose whether they prefer performance over memory fragmentation or not.
> Or maybe at the end of the partition method, if one of the result arrays is significantly smaller than the other, we copy the data into a smaller array and then return.

Oh, yeah… I was thinking the excess storage would be deallocated at the end anyway. Honestly, this whole bit about super-optimizing the memory allocation assumes that the actual element storage is managed like C arrays (with a pointer to [0], and using pointer math to get the other elements) behind the scenes, and I don’t actually know that it’s done that way.

- Dave Sweeris

More information about the swift-evolution mailing list