3 ms·
yes, the Iterator protocol of Java is sub-optimal - hasNext() has to be called twice so you hope the VM will kick the common sub expression elimination which i
by _old_dude_ 9y ago
yes, the Iterator protocol of Java is sub-optimal
- hasNext() has to be called twice so you hope the VM will kick the common sub expression elimination which i have found works well only if you do not do any side effect in hasNext.
- and most of the Iterator are fail fast so the code has to check that the modCount of the collection has not changed.
but from my own experience, you usually do not have to optimize that far, removing that 'synchronized' block, is far more common.