Need reviewer for forward port of 6815768 (File.getXXXSpace) and 6815768 (String.hashCode)

Ulf Zibis Ulf.Zibis at gmx.de
Fri Feb 26 15:25:24 UTC 2010


Am 26.02.2010 13:58, schrieb Alan Bateman:
> Jason Mehrens wrote:
>> Alan,
>>
>> Shouldn't the loading of 'this.count' into 'len' be only performed if 
>> 'h' is zero?  Otherwise, when hash is not zero we perform a little 
>> unnecessary work every time hashCode is called.
>>
>> Jason
> That's a good suggestion although it might be hard to measure any 
> difference.
>

In case of HotSpot compiled code, I guess, len will not be filled by 
this.count before it is actually needed, but in interpreted code Jason 
may be right.

So optimum could be:

public int hashCode() {
   int h = hash;
   if (h == 0) {
     int len = count;
     if (len>  0) {
       char[] val = value;
       for (int i = 0, off = offset; i<  len; i++)
         h = 31*h + val[off++];
       hash = h;
     }
   }
   return h;
}


- Ulf

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20100226/9973f7d0/attachment.html>


More information about the core-libs-dev mailing list