[Mono-dev] [U-SPAM] Re: String.GetHashCode()
apenwarr at gmail.com
Sun Dec 2 17:42:35 EST 2007
On 02/12/2007, Andreas Nahr <ClassDevelopment at a-softtech.com> wrote:
> Don't forget that 4 bytes per Hashcode isn't enough. You also need a boolean
> to store if the hash is already computed (as e.g. 0 is a valid hash, too).
> And then you would need one additional check for this boolean per call.
Technically it would be safe (and no worse than current behaviour) to
recalculate the hash every time in the rare case that it's exactly
> And don't forget that strings within the corelib ARE mutable to some extent.
That sounds somewhat more important.
Wouldn't it be better, in the cases where precomputing the hash would
have a large benefit, just to create a new class like
PrecomputedHashString that stores a string along with its hash? Then
the application itself could optimize for the cases where this matters
by using the different class as the key to its hash tables.
More information about the Mono-devel-list