mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-03 09:14:38 +00:00
Move more things to PtrMap
This commit is contained in:
@@ -699,7 +699,7 @@ struct TypeAndToken {
|
||||
};
|
||||
|
||||
|
||||
void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Operand operand, bool use_expr = true) {
|
||||
void add_constant_switch_case(CheckerContext *ctx, PtrMap<uintptr, TypeAndToken> *seen, Operand operand, bool use_expr = true) {
|
||||
if (operand.mode != Addressing_Constant) {
|
||||
return;
|
||||
}
|
||||
@@ -707,7 +707,7 @@ void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Oper
|
||||
return;
|
||||
}
|
||||
|
||||
HashKey key = hash_exact_value(operand.value);
|
||||
uintptr key = hash_exact_value(operand.value);
|
||||
TypeAndToken *found = map_get(seen, key);
|
||||
if (found != nullptr) {
|
||||
isize count = multi_map_count(seen, key);
|
||||
@@ -964,7 +964,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
||||
}
|
||||
}
|
||||
|
||||
Map<TypeAndToken> seen = {}; // NOTE(bill): Multimap, Key: ExactValue
|
||||
PtrMap<uintptr, TypeAndToken> seen = {}; // NOTE(bill): Multimap, Key: ExactValue
|
||||
map_init(&seen, heap_allocator());
|
||||
defer (map_destroy(&seen));
|
||||
|
||||
@@ -1133,8 +1133,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
||||
continue;
|
||||
}
|
||||
ExactValue v = f->Constant.value;
|
||||
HashKey key = hash_exact_value(v);
|
||||
auto found = map_get(&seen, key);
|
||||
auto found = map_get(&seen, hash_exact_value(v));
|
||||
if (!found) {
|
||||
array_add(&unhandled, f);
|
||||
}
|
||||
|
||||
@@ -290,13 +290,13 @@ struct StringIntern {
|
||||
char str[1];
|
||||
};
|
||||
|
||||
Map<StringIntern *> string_intern_map = {}; // Key: u64
|
||||
PtrMap<uintptr, StringIntern *> string_intern_map = {}; // Key: u64
|
||||
gb_global Arena string_intern_arena = {};
|
||||
|
||||
char const *string_intern(char const *text, isize len) {
|
||||
u64 hash = gb_fnv64a(text, len);
|
||||
u64 key = hash ? hash : 1;
|
||||
StringIntern **found = map_get(&string_intern_map, hash_integer(key));
|
||||
uintptr key = cast(uintptr)(hash ? hash : 1);
|
||||
StringIntern **found = map_get(&string_intern_map, key);
|
||||
if (found) {
|
||||
for (StringIntern *it = *found; it != nullptr; it = it->next) {
|
||||
if (it->len == len && gb_strncmp(it->str, (char *)text, len) == 0) {
|
||||
@@ -310,7 +310,7 @@ char const *string_intern(char const *text, isize len) {
|
||||
new_intern->next = found ? *found : nullptr;
|
||||
gb_memmove(new_intern->str, text, len);
|
||||
new_intern->str[len] = 0;
|
||||
map_set(&string_intern_map, hash_integer(key), new_intern);
|
||||
map_set(&string_intern_map, key, new_intern);
|
||||
return new_intern->str;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,44 +63,39 @@ struct ExactValue {
|
||||
|
||||
gb_global ExactValue const empty_exact_value = {};
|
||||
|
||||
HashKey hash_exact_value(ExactValue v) {
|
||||
uintptr hash_exact_value(ExactValue v) {
|
||||
mutex_lock(&hash_exact_value_mutex);
|
||||
defer (mutex_unlock(&hash_exact_value_mutex));
|
||||
|
||||
HashKey empty = {};
|
||||
switch (v.kind) {
|
||||
case ExactValue_Invalid:
|
||||
return empty;
|
||||
return 0;
|
||||
case ExactValue_Bool:
|
||||
return hash_integer(u64(v.value_bool));
|
||||
return gb_fnv32a(&v.value_bool, gb_size_of(v.value_bool));
|
||||
case ExactValue_String:
|
||||
{
|
||||
char const *str = string_intern(v.value_string);
|
||||
return hash_pointer(str);
|
||||
}
|
||||
return ptr_map_hash_key(string_intern(v.value_string));
|
||||
case ExactValue_Integer:
|
||||
{
|
||||
HashKey key = hashing_proc(v.value_integer.dp, gb_size_of(*v.value_integer.dp) * v.value_integer.used);
|
||||
u32 key = gb_fnv32a(v.value_integer.dp, gb_size_of(*v.value_integer.dp) * v.value_integer.used);
|
||||
u8 last = (u8)v.value_integer.sign;
|
||||
key.key = (key.key ^ last) * 0x100000001b3ll;
|
||||
return key;
|
||||
return (key ^ last) * 0x01000193;
|
||||
}
|
||||
case ExactValue_Float:
|
||||
return hash_f64(v.value_float);
|
||||
return gb_fnv32a(&v.value_float, gb_size_of(v.value_float));
|
||||
case ExactValue_Pointer:
|
||||
return hash_integer(v.value_pointer);
|
||||
return ptr_map_hash_key(v.value_pointer);
|
||||
case ExactValue_Complex:
|
||||
return hashing_proc(v.value_complex, gb_size_of(Complex128));
|
||||
return gb_fnv32a(v.value_complex, gb_size_of(Complex128));
|
||||
case ExactValue_Quaternion:
|
||||
return hashing_proc(v.value_quaternion, gb_size_of(Quaternion256));
|
||||
return gb_fnv32a(v.value_quaternion, gb_size_of(Quaternion256));
|
||||
case ExactValue_Compound:
|
||||
return hash_pointer(v.value_compound);
|
||||
return ptr_map_hash_key(v.value_compound);
|
||||
case ExactValue_Procedure:
|
||||
return hash_pointer(v.value_procedure);
|
||||
return ptr_map_hash_key(v.value_procedure);
|
||||
case ExactValue_Typeid:
|
||||
return hash_pointer(v.value_typeid);
|
||||
return ptr_map_hash_key(v.value_typeid);
|
||||
}
|
||||
return hashing_proc(&v, gb_size_of(ExactValue));
|
||||
return gb_fnv32a(&v, gb_size_of(ExactValue));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ template <typename K, typename V>
|
||||
PtrMapEntry<K, V> *multi_map_find_next(PtrMap<K, V> *h, PtrMapEntry<K, V> *e) {
|
||||
isize i = e->next;
|
||||
while (i != MAP_SENTINEL) {
|
||||
if (hash_key_equal(h->entries.data[i].key, e->key)) {
|
||||
if (h->entries.data[i].key == e->key) {
|
||||
return &h->entries.data[i];
|
||||
}
|
||||
i = h->entries.data[i].next;
|
||||
|
||||
Reference in New Issue
Block a user