A DenseMap doesn't store the hashes, so it needs to recompute them when the table is resized.
In some applications the hashing cost is noticeable. That is the case for example in lld for symbol names (StringRef).
This patch adds a templated structure that can wraps any value that can go in a DenseMap and caches the hash.
I think you can remove both of these constructors if you're going to use braced init anyway?
(though I guess maybe you need the first because you want implicit conversion from T -> CachedHash)
Also, any desire to make this do the right thing for movable types? I'd probably at least add the "Val(std::move(Val))" in the ctors (whichever ones you keep, if any). That still won't be great for expensive-to-move things, but they're less of a priority & hopefully we just fix them.