Benefit from computing String Hash at compile time?
Paul Benedict
pbenedict at apache.org
Sat Dec 19 16:30:54 PST 2009
> This is wasteful, first because strings used in switch statements and also
> in hashed collections will be hashed twice; second (and much more
> important), every execution switch(str) needs to call your special hashcode
> function again for str, as this hashcode cannot be cached in str. This extra
> cost makes switch-on-string O(N) on the str.length, which makes the hashing
> compilation strategy pointless.
You make a good point. As for being "hashed twice", that's simply the
cost of removing the reliance on String.hashCode(). Well, couldn't
$switch_hashCode() perform some caching for itself?
Paul
More information about the coin-dev
mailing list