You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by "mattbertolini (via GitHub)" <gi...@apache.org> on 2025/07/26 15:06:23 UTC

[PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

mattbertolini opened a new pull request, #223:
URL: https://github.com/apache/ant/pull/223

   I came across this while working on a custom Ant task. I saw what I think is the ResourceCollection stream() method eagerly loading elements when creating a stream. Not sure if that was intentional or not. If it is, feel free to close the PR.  If not, I've created this to update it to use the StreamSupport factory method and a spliterator. I think this is how the JDK Collection creates the stream. This will make using things like findFirst a bit faster as it won't have to load every element to find the first.


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "bodewig (via GitHub)" <gi...@apache.org>.
bodewig merged PR #223:
URL: https://github.com/apache/ant/pull/223


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "bodewig (via GitHub)" <gi...@apache.org>.
bodewig commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3192406821

   > I thought that "big commit" sounded familiar! 😀 Matt
   
   sorry :-)


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "mbenson (via GitHub)" <gi...@apache.org>.
mbenson commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3177605680

   I thought that "big commit" sounded familiar! 😀
   
   Matt
   
   On Mon, Aug 11, 2025, 8:47 PM Matt Bertolini ***@***.***>
   wrote:
   
   > *mattbertolini* left a comment (apache/ant#223)
   > <https://github.com/apache/ant/pull/223#issuecomment-3177420746>
   >
   > @bodewig <https://github.com/bodewig> Thank you for taking a look and for
   > this extra detail about the size and Spliterator. I agree that it would
   > make sense to override the spliterator() method to leverage the known
   > size. Worse case, for the filtered collections, it will have to iterate the
   > collection which is no worse than what the stream() method is doing now.
   >
   > I have updated the PR with the overloaded method. I think I got the
   > characteristics argument correct but a review of my assumptions is always
   > appreciated.
   >
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/ant/pull/223#issuecomment-3177420746>, or
   > unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AADXAJSPBHQOGCOSTRY4TPT3NFBUHAVCNFSM6AAAAACCNVPR56VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCNZXGQZDANZUGY>
   > .
   > You are receiving this because you are subscribed to this thread.Message
   > ID: ***@***.***>
   >
   


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "bodewig (via GitHub)" <gi...@apache.org>.
bodewig commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3199101476

   Thank you @mattbertolini 


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "bodewig (via GitHub)" <gi...@apache.org>.
bodewig commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3146588601

   Thank you.
   
   At first glance I don't believe there's been a reason to not use StreamSupport when the [big commit](https://github.com/apache/ant/commit/b7d1e9bde44cb8e5233d6e70bb96e14cbb2f3e2d) that moved us to Java 8 features was created.
   
   But then I was wondering whether we should override `spliterator` since we know `size()` and could do better than use the default. Which reminded me that some implementations don't know their size without iteration (filtered collections of any kind), Those collections use an internal cache to avoid repeated iterations (`MappedResourceCollection` for example). The default `spliterator` uses `iterator` if I understand correctly, so using StreamSupport the way you do should also be using the cache.


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "bodewig (via GitHub)" <gi...@apache.org>.
bodewig commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3192416577

   Thank you @mattbertolini , I'll try to find some time during the weekend to look through our implementations. Maybe, just maybe, it would be better to define `iterator` only in those subclasses that have a better idea of their size. I really need to look through the code to get a better feeling for it.


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "bodewig (via GitHub)" <gi...@apache.org>.
bodewig commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3194581653

   So here is what I see right now. There are ResourceCollection implementation where using `size` inside `spliterator` could perform a potentially expensive iteration twice. Everything that extends `ArchiveFileSet` will reread the full archive twice, for example, as would happen for everything that extends `BaseResourceCollectionContainer` if caching is disabled.
   
   It is probably better to use your initial PR. We could created sized iterators for some of the collections, but it is not safe in as many places as I thought it would be.
   
   Sorry for the additional effort I have caused.


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "mattbertolini (via GitHub)" <gi...@apache.org>.
mattbertolini commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3177420746

   @bodewig Thank you for taking a look and for this extra detail about the size and `Spliterator`. I agree that it would make sense to override the `spliterator()` method to leverage the known size. Worse case, for the filtered collections, it will have to iterate the collection which is no worse than what the `stream()` method is doing now.
   
   I have updated the PR with the overloaded method. I think I got the characteristics argument correct but a review of my assumptions is always appreciated. 


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [PR] Use StreamSupport and spliterator to create a stream for ResourceCollection [ant]

Posted by "mattbertolini (via GitHub)" <gi...@apache.org>.
mattbertolini commented on PR #223:
URL: https://github.com/apache/ant/pull/223#issuecomment-3198873425

   @bodewig Thank you for the detailed analysis. It was definitely more complex than I was originally thinking. No worries on the extra work. I'm happy to do it. I've reverted the spliterator change and have the original stream change back.


-- 
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: dev-unsubscribe@ant.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org