Possible HashMap update

Doug Lea dl at cs.oswego.edu
Wed Aug 14 11:16:23 UTC 2013

On 08/13/13 16:56, Remi Forax wrote:
>>>> And that the iterators on entrySet, keySet and values doesn't have their method
>>>> forEachRemaining overriden
>>>> (unlike java.util.ArrayList).
>> Are you saying that all iterators should define forEachRemaining?
>> Seems excessive.
> All iterators for ArrayList, HashMap and their views should have forEachRemaining,
> I don't care about the other collections :)
> forEachRemaining internally use local variables instead of fields as the
> traditional iterator does,
> so it may be faster than a plain old iterator loop. Moreover, the call to the
> Consumer inside
> the default method defined in Iterable can be megamorphic,
> if each iterator's view have they own implementation, you create a several of
> different callsites
> (I know, I know, it's a kind of poor's man optimization) that mitigates the
> profile pollution problem.

Could you explain exactly when these trigger? Most Stream-related
operations should pick up spliterator, not iterator, so won't
encounter this.

I resist this a bit because it would require 6 more
methods, each redundant with a spliterator method.
(The HashMap view ones must be overridden in LinkedHashMap.)
But if the situation is common, it might be worthwhile.


More information about the core-libs-dev mailing list