mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Clean up use of StringMap
This commit is contained in:
+4
-7
@@ -58,11 +58,8 @@ gb_internal void scope_reset(Scope *scope) {
|
|||||||
rw_mutex_unlock(&scope->mutex);
|
rw_mutex_unlock(&scope->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void scope_reserve(Scope *scope, isize capacity) {
|
gb_internal void scope_reserve(Scope *scope, isize count) {
|
||||||
isize cap = 2*capacity;
|
string_map_reserve(&scope->elements, 2*count);
|
||||||
if (cap > scope->elements.hashes.count) {
|
|
||||||
string_map_rehash(&scope->elements, capacity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) {
|
gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) {
|
||||||
@@ -4699,7 +4696,7 @@ gb_internal void check_collect_entities_all(Checker *c) {
|
|||||||
map_init(&wd->untyped);
|
map_init(&wd->untyped);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const &entry : c->info.files.entries) {
|
for (auto const &entry : c->info.files) {
|
||||||
AstFile *f = entry.value;
|
AstFile *f = entry.value;
|
||||||
thread_pool_add_task(check_collect_entities_all_worker_proc, f);
|
thread_pool_add_task(check_collect_entities_all_worker_proc, f);
|
||||||
}
|
}
|
||||||
@@ -4739,7 +4736,7 @@ gb_internal void check_export_entities(Checker *c) {
|
|||||||
wd->ctx = make_checker_context(c);
|
wd->ctx = make_checker_context(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto const &entry : c->info.packages.entries) {
|
for (auto const &entry : c->info.packages) {
|
||||||
AstPackage *pkg = entry.value;
|
AstPackage *pkg = entry.value;
|
||||||
thread_pool_add_task(check_export_entities_worker_proc, pkg);
|
thread_pool_add_task(check_export_entities_worker_proc, pkg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1625,6 +1625,7 @@ gb_internal bool lb_llvm_object_generation(lbGenerator *gen, bool do_threading)
|
|||||||
|
|
||||||
String filepath_ll = lb_filepath_ll_for_module(m);
|
String filepath_ll = lb_filepath_ll_for_module(m);
|
||||||
String filepath_obj = lb_filepath_obj_for_module(m);
|
String filepath_obj = lb_filepath_obj_for_module(m);
|
||||||
|
gb_printf_err("%.*s\n", LIT(filepath_obj));
|
||||||
array_add(&gen->output_object_paths, filepath_obj);
|
array_add(&gen->output_object_paths, filepath_obj);
|
||||||
array_add(&gen->output_temp_paths, filepath_ll);
|
array_add(&gen->output_temp_paths, filepath_ll);
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
|
|||||||
map_set(&gen->modules, cast(void *)pkg, m);
|
map_set(&gen->modules, cast(void *)pkg, m);
|
||||||
lb_init_module(m, c);
|
lb_init_module(m, c);
|
||||||
#else
|
#else
|
||||||
|
// NOTE(bill): Probably per file is not a good idea, so leave this for later
|
||||||
for (AstFile *file : pkg->files) {
|
for (AstFile *file : pkg->files) {
|
||||||
auto m = gb_alloc_item(permanent_allocator(), lbModule);
|
auto m = gb_alloc_item(permanent_allocator(), lbModule);
|
||||||
m->file = file;
|
m->file = file;
|
||||||
|
|||||||
+32
-41
@@ -35,8 +35,6 @@ struct StringMapEntry {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct StringMap {
|
struct StringMap {
|
||||||
using K = String;
|
|
||||||
using V = T;
|
|
||||||
Slice<MapIndex> hashes;
|
Slice<MapIndex> hashes;
|
||||||
Array<StringMapEntry<T> > entries;
|
Array<StringMapEntry<T> > entries;
|
||||||
};
|
};
|
||||||
@@ -53,15 +51,14 @@ template <typename T> gb_internal T & string_map_must_get (StringMap<T>
|
|||||||
template <typename T> gb_internal T & string_map_must_get (StringMap<T> *h, String const &key);
|
template <typename T> gb_internal T & string_map_must_get (StringMap<T> *h, String const &key);
|
||||||
template <typename T> gb_internal T & string_map_must_get (StringMap<T> *h, StringHashKey const &key);
|
template <typename T> gb_internal T & string_map_must_get (StringMap<T> *h, StringHashKey const &key);
|
||||||
|
|
||||||
template <typename T> gb_internal void string_map_set (StringMap<T> *h, StringHashKey const &key, T const &value);
|
|
||||||
template <typename T> gb_internal void string_map_set (StringMap<T> *h, String const &key, T const &value);
|
|
||||||
template <typename T> gb_internal void string_map_set (StringMap<T> *h, char const *key, T const &value);
|
template <typename T> gb_internal void string_map_set (StringMap<T> *h, char const *key, T const &value);
|
||||||
|
template <typename T> gb_internal void string_map_set (StringMap<T> *h, String const &key, T const &value);
|
||||||
|
template <typename T> gb_internal void string_map_set (StringMap<T> *h, StringHashKey const &key, T const &value);
|
||||||
|
|
||||||
template <typename T> gb_internal void string_map_remove (StringMap<T> *h, StringHashKey const &key);
|
// template <typename T> gb_internal void string_map_remove (StringMap<T> *h, StringHashKey const &key);
|
||||||
template <typename T> gb_internal void string_map_clear (StringMap<T> *h);
|
template <typename T> gb_internal void string_map_clear (StringMap<T> *h);
|
||||||
template <typename T> gb_internal void string_map_grow (StringMap<T> *h);
|
template <typename T> gb_internal void string_map_grow (StringMap<T> *h);
|
||||||
template <typename T> gb_internal void string_map_rehash (StringMap<T> *h, isize new_count);
|
template <typename T> gb_internal void string_map_reserve (StringMap<T> *h, isize new_count);
|
||||||
template <typename T> gb_internal void string_map_reserve (StringMap<T> *h, isize cap);
|
|
||||||
|
|
||||||
gb_internal gbAllocator string_map_allocator(void) {
|
gb_internal gbAllocator string_map_allocator(void) {
|
||||||
return heap_allocator();
|
return heap_allocator();
|
||||||
@@ -137,7 +134,7 @@ gb_internal b32 string_map__full(StringMap<T> *h) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
gb_inline void string_map_grow(StringMap<T> *h) {
|
gb_inline void string_map_grow(StringMap<T> *h) {
|
||||||
isize new_count = gb_max(h->hashes.count<<1, 16);
|
isize new_count = gb_max(h->hashes.count<<1, 16);
|
||||||
string_map_rehash(h, new_count);
|
string_map_reserve(h, new_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -172,12 +169,6 @@ gb_internal void string_map_reserve(StringMap<T> *h, isize cap) {
|
|||||||
string_map_reset_entries(h);
|
string_map_reset_entries(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
gb_internal void string_map_rehash(StringMap<T> *h, isize new_count) {
|
|
||||||
string_map_reserve(h, new_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal T *string_map_get(StringMap<T> *h, StringHashKey const &key) {
|
gb_internal T *string_map_get(StringMap<T> *h, StringHashKey const &key) {
|
||||||
MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL};
|
MapFindResult fr = {MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL};
|
||||||
@@ -259,34 +250,34 @@ gb_internal gb_inline void string_map_set(StringMap<T> *h, char const *key, T co
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
// template <typename T>
|
||||||
gb_internal void string_map__erase(StringMap<T> *h, MapFindResult const &fr) {
|
// gb_internal void string_map__erase(StringMap<T> *h, MapFindResult const &fr) {
|
||||||
MapFindResult last;
|
// MapFindResult last;
|
||||||
if (fr.entry_prev == MAP_SENTINEL) {
|
// if (fr.entry_prev == MAP_SENTINEL) {
|
||||||
h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next;
|
// h->hashes.data[fr.hash_index] = h->entries.data[fr.entry_index].next;
|
||||||
} else {
|
// } else {
|
||||||
h->entries.data[fr.entry_prev].next = h->entries.data[fr.entry_index].next;
|
// h->entries.data[fr.entry_prev].next = h->entries.data[fr.entry_index].next;
|
||||||
}
|
// }
|
||||||
if (fr.entry_index == h->entries.count-1) {
|
// if (fr.entry_index == h->entries.count-1) {
|
||||||
array_pop(&h->entries);
|
// array_pop(&h->entries);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
h->entries.data[fr.entry_index] = h->entries.data[h->entries.count-1];
|
// h->entries.data[fr.entry_index] = h->entries.data[h->entries.count-1];
|
||||||
last = string_map__find(h, h->entries.data[fr.entry_index].key);
|
// last = string_map__find(h, h->entries.data[fr.entry_index].key);
|
||||||
if (last.entry_prev != MAP_SENTINEL) {
|
// if (last.entry_prev != MAP_SENTINEL) {
|
||||||
h->entries.data[last.entry_prev].next = fr.entry_index;
|
// h->entries.data[last.entry_prev].next = fr.entry_index;
|
||||||
} else {
|
// } else {
|
||||||
h->hashes.data[last.hash_index] = fr.entry_index;
|
// h->hashes.data[last.hash_index] = fr.entry_index;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
template <typename T>
|
// template <typename T>
|
||||||
gb_internal void string_map_remove(StringMap<T> *h, StringHashKey const &key) {
|
// gb_internal void string_map_remove(StringMap<T> *h, StringHashKey const &key) {
|
||||||
MapFindResult fr = string_map__find(h, key);
|
// MapFindResult fr = string_map__find(h, key);
|
||||||
if (fr.entry_index != MAP_SENTINEL) {
|
// if (fr.entry_index != MAP_SENTINEL) {
|
||||||
string_map__erase(h, fr);
|
// string_map__erase(h, fr);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
gb_internal gb_inline void string_map_clear(StringMap<T> *h) {
|
gb_internal gb_inline void string_map_clear(StringMap<T> *h) {
|
||||||
|
|||||||
Reference in New Issue
Block a user