String.hash should only have two known states, zero and the actual computed hash code.
http://bugs.sun.com/view_bug.do?bug_id=6611830 Jason > Date: Sun, 28 Feb 2010 17:09:15 +0100 > From: ulf.zi...@gmx.de > To: alan.bate...@sun.com > Subject: Re: Need reviewer for forward port of 6815768 (File.getXXXSpace) and > 6815768 (String.hashCode) > CC: core-libs-dev@openjdk.java.net; dmitry.nadez...@gmail.com; > kelly.oh...@sun.com > > Another thought: > > In the constructors of String we could initialize hash = > Integer.MIN_VALUE except if length == 0. > Then we could stay at the fastest version: > > public int hashCode() { > int h = hash; > if (h == Integer.MIN_VALUE) { > h = 0; > char[] val = value; > for (int i = offset, limit = count + i; i != limit; ) > h = 31 * h + val[i++]; > hash = h; > } > return h; > } _________________________________________________________________ Hotmail: Trusted email with Microsoft’s powerful SPAM protection. http://clk.atdmt.com/GBL/go/201469226/direct/01/