+2001-04-08 Per Bothner <per@bothner.com>
+
+ * java/lang/natString.cc (_Jv_NewStringUtf8Const): Register finalizer.
+ Recalculate hash, since Utf8Const's hash is only 16 bits.
+
+ * java/lang/natString.cc (_Jv_StringFindSlot, rehash): Use high-order
+ bits of hash to calculate step for chaining.
+
+ * java/lang/natString.cc (intern, _Jv_NewStringUtf8Const): Rehash
+ when 2/3 full, rather than 3/4 full.
+
2001-04-06 Tom Tromey <tromey@redhat.com>
* jni.cc (wrap_value<jobject>, wrap_value<jclass>): Removed.
int index = start_index;
/* step must be non-zero, and relatively prime with strhash_size. */
- int step = 8 * hash + 7;
+ jint step = (hash ^ (hash >> 16)) | 1;
for (;;)
{
jstring* ptr = &strhash[index];
jstring val = (jstring) UNMASK_PTR (*ptr);
jint hash = val->hashCode();
jint index = hash & (nsize - 1);
- jint step = 8 * hash + 7;
+ jint step = (hash ^ (hash >> 16)) | 1;
for (;;)
{
if (next[index] == NULL)
java::lang::String::intern()
{
JvSynchronize sync (&StringClass);
- if (4 * strhash_count >= 3 * strhash_size)
+ if (3 * strhash_count >= 2 * strhash_size)
rehash();
jstring* ptr = _Jv_StringGetSlot(this);
if (*ptr != NULL && *ptr != DELETED_STRING)
chrs = JvGetStringChars(jstr);
}
+ jint hash = 0;
while (data < limit)
- *chrs++ = UTF8_GET(data, limit);
+ {
+ jchar ch = UTF8_GET(data, limit);
+ hash = (31 * hash) + ch;
+ *chrs++ = ch;
+ }
chrs -= length;
JvSynchronize sync (&StringClass);
- if (4 * strhash_count >= 3 * strhash_size)
+ if (3 * strhash_count >= 2 * strhash_size)
java::lang::String::rehash();
- int hash = str->hash;
jstring* ptr = _Jv_StringFindSlot (chrs, length, hash);
if (*ptr != NULL && *ptr != DELETED_STRING)
return (jstring) UNMASK_PTR (*ptr);
}
*ptr = jstr;
SET_STRING_IS_INTERNED(jstr);
+ // When string is GC'd, clear the slot in the hash table.
+ _Jv_RegisterFinalizer ((void *) jstr, unintern);
return jstr;
}