Skip to content

Add .size_hint() implementation for ArchiveSymbolIterator#759

Merged
philipc merged 2 commits intogimli-rs:masterfrom
MEhrn00:ar-symbol-sizehint
Mar 12, 2025
Merged

Add .size_hint() implementation for ArchiveSymbolIterator#759
philipc merged 2 commits intogimli-rs:masterfrom
MEhrn00:ar-symbol-sizehint

Conversation

@MEhrn00
Copy link
Copy Markdown
Contributor

@MEhrn00 MEhrn00 commented Mar 2, 2025

This PR adds a .size_hint() implementation to the ArchiveSymbolIterator.

The value returned for this is the size hint value of the underlying slice::Iter. This provides the most accurate size hint without needing to add additional fields for keeping track of the iterator's state.

I have been working on a project where it would be nice to pre-allocate collections based on the number of symbols inside an archive's symbol map. The default .size_hint() implementation returns 0 and there is no API in this library that will get this value.

This uses the size hint value from the underlying `slice::Iter`. The
iterator itself does not track the symbol count so this slice iter
provides the most accurate value
Changes the size_hint() implementation in the archive symbol iterator
to use the '..' syntax for unused fields
@MEhrn00 MEhrn00 requested a review from philipc March 11, 2025 14:11
Copy link
Copy Markdown
Contributor

@philipc philipc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@philipc philipc merged commit 975587b into gimli-rs:master Mar 12, 2025
10 checks passed
@MEhrn00 MEhrn00 deleted the ar-symbol-sizehint branch April 8, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants