mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Started working on Toy_Scope, incomplete
I only worked for a couple hours today.
This commit is contained in:
@@ -70,18 +70,7 @@ bool Toy_private_isEqual(Toy_Value left, Toy_Value right) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//hash utils
|
||||
static unsigned int hashCString(const char* string) {
|
||||
unsigned int hash = 2166136261u;
|
||||
|
||||
for (unsigned int i = 0; string[i]; i++) {
|
||||
hash *= string[i];
|
||||
hash ^= 16777619;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
//hash util
|
||||
static unsigned int hashUInt(unsigned int x) {
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
x = ((x >> 16) ^ x) * 0x45d9f3b;
|
||||
@@ -89,7 +78,6 @@ static unsigned int hashUInt(unsigned int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Toy_hashValue(Toy_Value value) {
|
||||
switch(value.type) {
|
||||
case TOY_VALUE_NULL:
|
||||
@@ -104,27 +92,8 @@ unsigned int Toy_hashValue(Toy_Value value) {
|
||||
case TOY_VALUE_FLOAT:
|
||||
return hashUInt( *((int*)(&TOY_VALUE_AS_FLOAT(value))) );
|
||||
|
||||
case TOY_VALUE_STRING: {
|
||||
Toy_String* str = TOY_VALUE_AS_STRING(value);
|
||||
|
||||
if (str->cachedHash != 0) {
|
||||
return str->cachedHash;
|
||||
}
|
||||
else if (str->type == TOY_STRING_NODE) {
|
||||
//TODO: I wonder if it would be possible to discretely swap the composite node string with a new leaf string here? Would that speed up other parts of the code by not having to walk the tree in future?
|
||||
char* buffer = Toy_getStringRawBuffer(str);
|
||||
str->cachedHash = hashCString(buffer);
|
||||
free(buffer);
|
||||
}
|
||||
else if (str->type == TOY_STRING_LEAF) {
|
||||
str->cachedHash = hashCString(str->as.leaf.data);
|
||||
}
|
||||
else if (str->type == TOY_STRING_NAME) {
|
||||
str->cachedHash = hashCString(str->as.name.data);
|
||||
}
|
||||
|
||||
return str->cachedHash;
|
||||
}
|
||||
case TOY_VALUE_STRING:
|
||||
return Toy_hashString(TOY_VALUE_AS_STRING(value));
|
||||
|
||||
case TOY_VALUE_ARRAY:
|
||||
case TOY_VALUE_DICTIONARY:
|
||||
|
||||
Reference in New Issue
Block a user