Simplify Map and StringMap in the compiler to reuse the hashes' array data if possible.

This commit is contained in:
gingerBill
2021-08-08 13:56:40 +01:00
parent 9cfe20cfb4
commit a5605e94b1
3 changed files with 55 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
#define ARRAY_GROW_FORMULA(x) (2*(x) + 8)
#define ARRAY_GROW_FORMULA(x) (gb_max(((x)+1)*3 >> 1, 8))
GB_STATIC_ASSERT(ARRAY_GROW_FORMULA(0) > 0);
#if 1
@@ -84,6 +84,23 @@ Slice<T> slice_make(gbAllocator const &allocator, isize count) {
return s;
}
template <typename T>
void slice_init(Slice<T> *s, gbAllocator const &allocator, isize count) {
s->data = gb_alloc_array(allocator, T, count);
s->count = count;
}
template <typename T>
void slice_free(Slice<T> *s, gbAllocator const &allocator) {
gb_free(allocator, s->data);
}
template <typename T>
void slice_resize(Slice<T> *s, gbAllocator const &allocator, isize new_count) {
resize_array_raw(&s->data, allocator, s->count, new_count);
s->count = new_count;
}
template <typename T>
Slice<T> slice_from_array(Array<T> const &a) {