diff options
| author | gingerBill <bill@gingerbill.org> | 2021-08-08 13:56:40 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-08-08 13:56:40 +0100 |
| commit | a5605e94b135464b50ab7d3e4dcb31d64e9e53fb (patch) | |
| tree | 47af653b83d92185fb313253d378cf1981ce88c1 /src/array.cpp | |
| parent | 9cfe20cfb4b7a99c8ed250f16b4856f9af11905a (diff) | |
Simplify `Map` and `StringMap` in the compiler to reuse the hashes' array data if possible.
Diffstat (limited to 'src/array.cpp')
| -rw-r--r-- | src/array.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/array.cpp b/src/array.cpp index ad0efcd74..90d85563c 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -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) { |