Skip to content

Optimize withAll on MutableIntBagFactoryImpl and ImmutableIntBagFactoryImpl #1372

@donraab

Description

@donraab

The code currently in withAll on both mutable and immutable implementations calls toArray on IntStream which if the Stream is very large can be extremely expensive and won't take advantage of a Bag's ability to store duplicates as simply increments in a count.

Current mutable factory code:

public MutableIntBag withAll(IntStream items)
{
    return this.with(items.toArray());
}

Current immutable factory code:

public ImmutableIntBag withAll(IntStream items)
{
    return this.with(items.toArray());
}

It would be much better to simply iterate over the Stream and add the results to a HashBag, converting to an ImmutableBag in the immutable factory.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions