History

Fixed string hashcode generation

Dmitry Kabak (userdima committed 13 years ago

Commit 45652ca1 parent a4e36b21 file · +5 −10Browse files

Showing the changes to java (1 of 1 file). Show all

Unified · Split

java/pkg/java/lang/String_L.b+5−10
@@ -214,21 +214,16 @@ regionMatches_Z_I_rString_I_I_Z( this : JString, p0 : int,p1 : int,p2 : JString, · 213 unmodified lines
214214
215215 hashCode_I( this : JString) : int
216216 {#>>
217− # hashcode of string as defined in JLS
217+ # hashcode of string as say java docs
218218 strhash := 0;
219219 this_str := this.str;
220220 this_len := len this_str;
221221
222− if ( this_len <= 15 )
222+ curmult := 1;
223+ for (i := this_len - 1; i >= 0; i--)
223224 {
224− for(x:=0; x<this_len; x++)
225− strhash = (strhash*37) + this_str[x];
226− }
227− else
228− {
229− k := int (this_len/8);
230− for(x:=0; x < this_len; x+=k)
231− strhash = (strhash*39) + this_str[x];
225+ strhash += this_str[i] * curmult;
226+ curmult *= 31;
232227 }
233228
234229 return( strhash );