Showing the changes to java (1 of 1 file). Show all
Unified · Split
| @@ -214,21 +214,16 @@ regionMatches_Z_I_rString_I_I_Z( this : JString, p0 : int,p1 : int,p2 : JString, · 213 unmodified lines | ||
| 214 | 214 | |
| 215 | 215 | hashCode_I( this : JString) : int |
| 216 | 216 | {#>> |
| 217 | − # hashcode of string as defined in JLS | |
| 217 | + # hashcode of string as say java docs | |
| 218 | 218 | strhash := 0; |
| 219 | 219 | this_str := this.str; |
| 220 | 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 = (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; | |
| 232 | 227 | } |
| 233 | 228 | |
| 234 | 229 | return( strhash ); |