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
214 214
215hashCode_I( this : JString) : int215hashCode_I( this : JString) : int
216{#>>216{#>>
217 # hashcode of string as defined in JLS217 # hashcode of string as say java docs
218 strhash := 0;218 strhash := 0;
219 this_str := this.str;219 this_str := this.str;
220 this_len := len this_str;220 this_len := len this_str;
221 221
222 if ( this_len <= 15 )222 curmult := 1;
223 for (i := this_len - 1; i >= 0; i--)
223 {224 {
224 for(x:=0; x<this_len; x++)225 strhash += this_str[i] * curmult;
225 strhash = (strhash*37) + this_str[x];226 curmult *= 31;
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];
232 }227 }
233 228
234 return( strhash );229 return( strhash );