Need reviewer for forward port of 6815768 (File.getXXXSpace) and 6815768 (String.hashCode)
Ulf Zibis
Ulf.Zibis at gmx.de
Sun Feb 28 16:09:15 UTC 2010
Am 25.02.2010 23:07, schrieb Alan Bateman:
> Kelly O'Hair wrote:
>> Yup. My eyes must be tired, I didn't see that. :^(
> Too many repositories in the air at the same time. The webrev has been
> refreshed. Thanks Ulf.
>
>
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;
}
As an alternative we could use:
private static final int UNKNOWN_HASH = 1;
Justification:
Using a small value results in little shorter byte code and machine code
footprint after compilation.
Additionally on some CPU's this likely will perform little better, but
never worse.
Please note:
Original loop causes 2 values to increment:
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
This is inefficient as I have proved in a little micro-benchmark.
-Ulf
More information about the core-libs-dev
mailing list