ppkarwasz commented on code in PR #633:
URL: 
https://github.com/apache/commons-collections/pull/633#discussion_r2265407892


##########
src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java:
##########
@@ -183,9 +188,12 @@ private void checkLocked() {
     @Override
     public boolean hasNext() {
         lockChain();
-        updateCurrentIterator();
-        lastUsedIterator = currentIterator;
-        return currentIterator.hasNext();
+        if (cachedHasNextValue == null) {
+            updateCurrentIterator();
+            lastUsedIterator = currentIterator;
+            cachedHasNextValue = currentIterator.hasNext();

Review Comment:
   This still results in two `hasNext()` calls for each element: the first 
happens inside `updateCurrentIterator()`, and the second is the explicit call 
here. That means the double-invocation issue (and its performance impact) 
remains. We should refactor so that `hasNext()` is only called **once** per 
element.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to