Javap shows different byte code for hashCode7 vs hashCode1 when I compiled and compared them. I'll have not tried jclasslib.
I agree with you on version 7 should be faster than version 6. However, in version 6 count is only loaded twice when running the path rarely chosen. I think that makes version 6 a good candidate to benchmark. Jason Date: Sat, 27 Feb 2010 19:11:05 +0100 From: ulf.zi...@gmx.de To: jason_mehr...@hotmail.com CC: dmitry.nadez...@gmail.com; core-libs-dev@openjdk.java.net Subject: Re: Need reviewer for forward port of 6815768 (File.getXXXSpace) and 6815768 (String.hashCode) Hm, hashCode7() has exactly the same program logic than hashCode1(), but by different syntax. hashCode8() should be worse than hashCode7(), because it loads the count variable twice. If you compare the byte code by javah or jclasslib bytecode viewer (very nice tool), you will see that, am I wrong ? -Ulf Am 27.02.2010 18:50, schrieb Jason Mehrens: Here are two more variants you might want to throw into the benchmark. public int hashCode6() { int h = hash; if (h == 0 && count > 0) { int off = offset; char val[] = value; int len = count; for (int i = 0; i < len; i++) { h = 31*h + val[off++]; } hash = h; } return h; } public int hashCode7() { int h = hash; int len; if (h == 0 && (len = count) > 0) { int off = offset; char val[] = value; for (int i = 0; i < len; i++) { h = 31*h + val[off++]; } hash = h; } return h; } Jason _________________________________________________________________ Hotmail: Trusted email with powerful SPAM protection. http://clk.atdmt.com/GBL/go/201469227/direct/01/