mirror of https://github.com/mgba-emu/mgba.git
Scripting: Fix scalar hashing on different union layouts, e.g. big endian
This commit is contained in:
parent
dfe9177374
commit
ea5db5f72d
|
@ -364,24 +364,6 @@ static uint32_t _hashString(const struct mScriptValue* val) {
|
||||||
return hash32(buffer, size, 0);
|
return hash32(buffer, size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t _hashScalar(const struct mScriptValue* val) {
|
|
||||||
// From https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key
|
|
||||||
uint32_t x = 0;
|
|
||||||
switch (val->type->base) {
|
|
||||||
case mSCRIPT_TYPE_SINT:
|
|
||||||
x = val->value.s32;
|
|
||||||
break;
|
|
||||||
case mSCRIPT_TYPE_UINT:
|
|
||||||
default:
|
|
||||||
x = val->value.u32;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
x = ((x >> 16) ^ x) * 0x45D9F3B;
|
|
||||||
x = ((x >> 16) ^ x) * 0x45D9F3B;
|
|
||||||
x = (x >> 16) ^ x;
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _wstrCast(const struct mScriptValue* input, const struct mScriptType* type, struct mScriptValue* output) {
|
bool _wstrCast(const struct mScriptValue* input, const struct mScriptType* type, struct mScriptValue* output) {
|
||||||
if (input->type->base != mSCRIPT_TYPE_WRAPPER) {
|
if (input->type->base != mSCRIPT_TYPE_WRAPPER) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -519,6 +501,16 @@ bool _castScalar(const struct mScriptValue* input, const struct mScriptType* typ
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t _hashScalar(const struct mScriptValue* val) {
|
||||||
|
// From https://stackoverflow.com/questions/664014/what-integer-hash-function-are-good-that-accepts-an-integer-hash-key
|
||||||
|
uint32_t x = 0;
|
||||||
|
_asUInt32(val, &x);
|
||||||
|
x = ((x >> 16) ^ x) * 0x45D9F3B;
|
||||||
|
x = ((x >> 16) ^ x) * 0x45D9F3B;
|
||||||
|
x = (x >> 16) ^ x;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t _valHash(const void* val, size_t len, uint32_t seed) {
|
uint32_t _valHash(const void* val, size_t len, uint32_t seed) {
|
||||||
UNUSED(len);
|
UNUSED(len);
|
||||||
const struct mScriptValue* value = val;
|
const struct mScriptValue* value = val;
|
||||||
|
|
Loading…
Reference in New Issue