mirror of
https://github.com/openjdk/jdk8u.git
synced 2025-12-10 20:07:00 -06:00
8310026: [8u] make java_lang_String::hash_code consistent across platforms
Reviewed-by: phh, adinn, stuefe
This commit is contained in:
parent
108003eb37
commit
15077ad189
@ -63,7 +63,7 @@ public class Hashtable extends BasicHashtable {
|
||||
int len = buf.length;
|
||||
// Emulate the unsigned int in java_lang_String::hash_code
|
||||
while (len-- > 0) {
|
||||
h = 31*h + (0xFFFFFFFFL & buf[s]);
|
||||
h = 31*h + (0xFFL & buf[s]);
|
||||
s++;
|
||||
}
|
||||
return h & 0xFFFFFFFFL;
|
||||
|
||||
@ -177,7 +177,7 @@ class java_lang_String : AllStatic {
|
||||
// hash P(31) from Kernighan & Ritchie
|
||||
//
|
||||
// For this reason, THIS ALGORITHM MUST MATCH String.hashCode().
|
||||
template <typename T> static unsigned int hash_code(T* s, int len) {
|
||||
static unsigned int hash_code(const jchar* s, int len) {
|
||||
unsigned int h = 0;
|
||||
while (len-- > 0) {
|
||||
h = 31*h + (unsigned int) *s;
|
||||
@ -185,6 +185,16 @@ class java_lang_String : AllStatic {
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static unsigned int hash_code(const jbyte* s, int len) {
|
||||
unsigned int h = 0;
|
||||
while (len-- > 0) {
|
||||
h = 31*h + (((unsigned int) *s) & 0xFF);
|
||||
s++;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static unsigned int hash_code(oop java_string);
|
||||
|
||||
// This is the string hash code used by the StringTable, which may be
|
||||
|
||||
@ -225,7 +225,7 @@ Symbol* SymbolTable::lookup(int index, const char* name,
|
||||
unsigned int SymbolTable::hash_symbol(const char* s, int len) {
|
||||
return use_alternate_hashcode() ?
|
||||
AltHashing::halfsiphash_32(seed(), (const uint8_t*)s, len) :
|
||||
java_lang_String::hash_code(s, len);
|
||||
java_lang_String::hash_code((const jbyte*)s, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user