Specialized Iterable.forEach implementations

9 views
Skip to first unread message

Scott Kilpatrick

unread,
Mar 1, 2020, 2:25:31 PM3/1/20
to fastutil
Hi there,

The fastutil ___Iterable interfaces define a `void forEach(CONSUMER action)` overloading where CONSUMER is some primitive consumer type, with a default implementation in terms of the underlying iterator. For many concrete ___Iterable implementations in fastutil, however, there are more straightforward implementations of `forEach` that don't incur the cost of the `hasNext`/`next` dance -- and allocations -- of those iterators. ___ArrayList is an example where a specialized `forEach` implementation without iterators is very straightforward.

To address that gap in fastutil, I'm currently working on a local clone to override the `forEach` method for all the Iterable implementations across fastutil: the iterables themselves but also any iterable implementations returned as part of other collections, like Map key, value, and entry sets. It's largely a straightforward addition since they each fall out of the iterator implementations.

Does anyone have any concerns or advice about making this change?

Best,
Scott
Reply all
Reply to author
Forward
0 new messages