In functions like filter and intersection we allocate a mutable array, fill it as needed, then shrink it and return it as a BitmapIndexed or Full node.
I wonder whether we could reduce these allocations by starting out with a bitmap that records which subnodes we keep or remove. Only once we encounter a node that is changed, e.g. a BitmapIndexed node reduced to a Leaf, we allocate an array for the result.
In functions like
filterandintersectionwe allocate a mutable array, fill it as needed, then shrink it and return it as aBitmapIndexedorFullnode.I wonder whether we could reduce these allocations by starting out with a bitmap that records which subnodes we keep or remove. Only once we encounter a node that is changed, e.g. a
BitmapIndexednode reduced to a Leaf, we allocate an array for the result.