Re: Tune String's hashCode() + equals()

2010-03-04 Thread Ulf Zibis
Am 04.03.2010 23:38, schrieb Marek Kozieł: 2010/3/4 Ulf Zibis: 5. Intern string do not need hash codes co comparing cos they have same address, so first loop would return true if they are equal, after this we need only to check if they are not equal: if (isIntern()&&anotherStr

Re: Tune String's hashCode() + equals()

2010-03-04 Thread Marek Kozieł
2010/3/4 Ulf Zibis : >> 5. >> Intern string do not need hash codes co comparing cos they have same >> address, so first loop would return true if they are equal, after this >> we need only to check if they are not equal: >> >>> >>> if (isIntern()&&  anotherString.isIntern()) return false; >>> > >

Re: Tune String's hashCode() + equals()

2010-03-04 Thread Ulf Zibis
Much thanks for your effort. Am 04.03.2010 21:31, schrieb Marek Kozieł: @Ulf Few explanations: 1. Intersting alternative, but I'm afraid, this is against the spec. Shifting all 0's to 1 would break String's hash definition: h = 31 * h + val[i++]. Yes it does, any way i think spec i

Re: Tune String's hashCode() + equals() [was: Need reviewer for forward port of 6815768 (File.getXXXSpace) and 6815768 (String.hashCode)]

2010-03-04 Thread Marek Kozieł
@Ulf Few explanations: 1. > Intersting alternative, but I'm afraid, this is against the spec. > Shifting all 0's to 1 would break String's hash definition: h = 31 * h + > val[i++]. Yes it does, any way i think spec is to tight here. Do we really need hash of each value even if String have length

Re: Tune String's hashCode() + equals() [was: Need reviewer for forward port of 6815768 (File.getXXXSpace) and 6815768 (String.hashCode)]

2010-03-04 Thread Ulf Zibis
Am 04.03.2010 19:33, schrieb Marek Kozieł: Hello, I would suggest: public int hashCode() { int h = hash; if (h == 0) { h = 0; char[] val = value; for (int i = offset, limit = count + i; i != limit; ) h = 31 * h + val[i++];