4 ms·
Yes, it will do exactly that.
by CAMLORN 10y ago
Yes, it will do exactly that.
- frankmcsherry 9y agoI think in this case it doesn't, because the `HashMap` implementation just stores everything behind an untyped pointer. https://github.com/rust-lang/rust/blob/master/src/libstd/collections/hash/table.rs#L115-L123 https://github.com/rust-lang/rust/blob/master/src/libstd/col... It would be cool to see if the "we'll manage our own pointers, thanks" approach makes less sense with this optimization in place. It would be nice; the source is pretty inscrutable, mostly in the interest of performance, I think. Edit: Or, maybe more importantly: in the untyped memory they store hashes and (K,V) pairs separately, so I think the only opportunity is to swap (K,V) for (V,K).
- CAMLORN 9y agoI haven't looked at libstd, so I can't comment to that specifically. But we don't reorder two-field structs. Rustc special cases them in a lot of places to do things that I will not even pretend to understand, and not reordering 2-element structs keeps them working. Since this already took 6 months of my free time (I have a lot of free time, though not 40 hours a week admittedly), this was for the best. You can make an argument that we should have, but it doesn't matter from the user's perspective. (a, b) is the same size as (b, a) no matter what a and b are.