mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 11:50:07 +00:00
Minor changes to StringMap allocation
This commit is contained in:
@@ -509,7 +509,7 @@ gb_internal GB_ALLOCATOR_PROC(heap_allocator_proc) {
|
||||
|
||||
|
||||
template <typename T>
|
||||
gb_internal isize resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count) {
|
||||
gb_internal isize resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count, isize custom_alignment=1) {
|
||||
GB_ASSERT(new_count >= 0);
|
||||
if (new_count == 0) {
|
||||
gb_free(a, *array);
|
||||
@@ -521,7 +521,7 @@ gb_internal isize resize_array_raw(T **array, gbAllocator const &a, isize old_co
|
||||
}
|
||||
isize old_size = old_count * gb_size_of(T);
|
||||
isize new_size = new_count * gb_size_of(T);
|
||||
isize alignment = gb_align_of(T);
|
||||
isize alignment = gb_max(gb_align_of(T), custom_alignment);
|
||||
auto new_data = cast(T *)gb_resize_align(a, *array, old_size, new_size, alignment);
|
||||
GB_ASSERT(new_data != nullptr);
|
||||
*array = new_data;
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ gb_internal Array<Ast *> clone_ast_array(Array<Ast *> const &array, AstFile *f)
|
||||
gb_internal Slice<Ast *> clone_ast_array(Slice<Ast *> const &array, AstFile *f) {
|
||||
Slice<Ast *> result = {};
|
||||
if (array.count > 0) {
|
||||
result = slice_clone(permanent_allocator(), array);
|
||||
result = slice_clone(ast_allocator(nullptr), array);
|
||||
for_array(i, array) {
|
||||
result[i] = clone_ast(array[i], f);
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,5 +1,11 @@
|
||||
GB_STATIC_ASSERT(sizeof(MapIndex) == sizeof(u32));
|
||||
|
||||
enum {
|
||||
STRING_MAP_CACHE_LINE_SIZE_POW = 6,
|
||||
STRING_MAP_CACHE_LINE_SIZE = 1<<STRING_MAP_CACHE_LINE_SIZE_POW,
|
||||
STRING_MAP_CACHE_LINE_MASK = STRING_MAP_CACHE_LINE_SIZE-1,
|
||||
};
|
||||
|
||||
struct StringHashKey {
|
||||
u32 hash;
|
||||
String string;
|
||||
@@ -79,13 +85,13 @@ gb_internal gb_inline void string_map_destroy(StringMap<T> *h) {
|
||||
|
||||
template <typename T>
|
||||
gb_internal void string_map__resize_hashes(StringMap<T> *h, usize count) {
|
||||
h->hashes_count = cast(u32)resize_array_raw(&h->hashes, string_map_allocator(), h->hashes_count, count);
|
||||
h->hashes_count = cast(u32)resize_array_raw(&h->hashes, string_map_allocator(), h->hashes_count, count, STRING_MAP_CACHE_LINE_SIZE);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
gb_internal void string_map__reserve_entries(StringMap<T> *h, usize capacity) {
|
||||
h->entries_capacity = cast(u32)resize_array_raw(&h->entries, string_map_allocator(), h->entries_capacity, capacity);
|
||||
h->entries_capacity = cast(u32)resize_array_raw(&h->entries, string_map_allocator(), h->entries_capacity, capacity, STRING_MAP_CACHE_LINE_SIZE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user