Skip to content

Refactor SocketIterator for allocation-free performance - #945

Merged
bee-san merged 2 commits into
bee-san:masterfrom
syed-ghufran-hassan:patch-2
Oct 1, 2026
Merged

bee-san merged 2 commits into
bee-san:masterfrom
syed-ghufran-hassan:patch-2

Conversation

@syed-ghufran-hassan

Copy link
Copy Markdown
Contributor

Refactor SocketIterator to eliminate boxing and improve memory efficiency. Update documentation and tests to reflect changes.

Refactor SocketIterator to eliminate boxing and improve memory efficiency. Update documentation and tests to reflect changes.
@syed-ghufran-hassan

Copy link
Copy Markdown
Contributor Author

@bee-san for your review please

…example

- clone_resumes_independently expected None after 3 of 4 sockets; assert
  the exact remaining sequence for both the original and the clone.
- The struct doc example referenced a placeholder crate and a private
  module, so it could never compile as a doctest; mark it ignore.
- Add a test for empty IP/port inputs covering size_hint and the
  FusedIterator promise.

@bee-san bee-san left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @syed-ghufran-hassan, nice cleanup! Dropping the Boxes and delegating size_hint is a clear win.

What I checked:

  • Same sockets, same order: it's still iproduct!(ports, ips), so every IP for one port comes before the next port, with nothing dropped or duplicated. 0 IPs or 0 ports yields nothing, and size_hint uses itertools' saturating/checked math, so large ranges can't overflow or panic.
  • No new network side effects. The iterator only builds SocketAddrs, and the call sites in scanner/mod.rs are unchanged.
  • cargo fmt --check, clippy -D warnings and cargo doc are clean, and CI is green on all 4 platforms.

I pushed one small fix commit (065ae7c) to get CI passing. clone_resumes_independently expected None while one socket was still left (2×2 = 4, one consumed before the clone, so 3 remain). The struct doc example imported your_crate and lives in a private module, so it could never compile as a doctest; I marked it ignore. I also added a small test for empty inputs.

@bee-san
bee-san merged commit cfb8645 into bee-san:master Oct 1, 2026
4 checks passed
@syed-ghufran-hassan

Copy link
Copy Markdown
Contributor Author

Thank you @bee-san

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