hyperium / http

Rust HTTP types
Apache License 2.0
1.14k stars 284 forks source link

Extend impls for HeaderMap don't use reserve #517

Open jplatte opened 2 years ago

jplatte commented 2 years ago

Is it intentional that the Extend implementations for HeaderMap don't call .reserve before starting iteration and insertion?

seanmonstar commented 2 years ago

I don't recall that it's intentional. What does std do with HashMap? Are you supposed to call reserve first, as a user? Or does it do it automatically? Whichever it does, we should follow suit.

jplatte commented 2 years ago

hashbrown does reserve up-front, though not as much as Vec because some items may be duplicate and not need extra capacity: https://docs.rs/hashbrown/0.11.2/src/hashbrown/map.rs.html#3392-3407

This leads me to a question actually, does HeaderMap's reserve reserve space for <amount> header names or <amount> header values? The docs don't say so explicitly, though I would assume the former without thinking much about it since the naive implementation of a multimap would basically be HashMap<K, Vec<V>>.