http icon indicating copy to clipboard operation
http copied to clipboard

Extend impls for HeaderMap don't use reserve

Open jplatte opened this issue 4 years ago • 2 comments

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

jplatte avatar Dec 21 '21 11:12 jplatte

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.

seanmonstar avatar Dec 21 '21 20:12 seanmonstar

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>>.

jplatte avatar Dec 22 '21 11:12 jplatte