bug report in String.hashCode()
Eric Pouech
eric.pouech at hol.fr
Wed Aug 5 03:52:35 PDT 1998
the code of String.hashCode() (in
librairies/javalib/java/lang/String.java) is not correct (1 character
string always return a hash value of 0).
it seems that :
- for string < 15 characters, the first character is never used in
computing hash value
Please find enclosed a diff -u that should solve this issue (the code
should behave the same as in kaffe/kaffevm/string.c (hashUtf8String()
for hashing Utf8 strings)
+++ String.java Wed Aug 5 08:12:37 1998
--- String.java.orig Wed Aug 5 08:13:21 1998
@@ -227,12 +227,12 @@
int hash = 0;
if ( count <= 15 ) {
- for ( i=offset+1; i<n; i++ )
+ for ( i=offset; i<n; i++ )
hash = (37 * hash) + value[i];
}
else {
int skip = count / 8;
- for ( i=offset+skip; i<n; i+=skip )
+ for ( i=offset+skip-1; i<n; i+=skip )
hash = (39 * hash) + value[i];
}
return hash;
--
--------------------
Eric Pouech (eric.pouech at lemel.fr)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://kaffe.org/pipermail/kaffe/attachments/19980805/3375b6ee/attachment-0020.htm
More information about the kaffe
mailing list