Skip to content

Conversation

@AriajSarkar
Copy link
Contributor

Summary

Fixes #517 by adding reserve() to Extend<(Option<HeaderName>, T)> to match Extend<(HeaderName, T)>.

Changes

  • Added reserve logic following hashbrown HashMap pattern
  • Reserves full hint for empty maps, half for non-empty (handles duplicates)
  • Ensures max 2 reallocations

Testing

✅ All 396 tests pass (no behavioral changes)

Code

let reserve = if self.is_empty() {
    iter.size_hint().0
} else {
    (iter.size_hint().0 + 1) / 2
};
self.reserve(reserve);

@AriajSarkar AriajSarkar changed the title feat: optimize capacity reservation in HeaderMap's extend method fix: Add reserve() to Extend impl for (Option<HeaderName>, T)) Oct 28, 2025
@seanmonstar seanmonstar merged commit 56a365b into hyperium:master Oct 28, 2025
10 checks passed
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.

Extend impls for HeaderMap don't use reserve

2 participants