From df640dc7f55fef962b598562e10d8dd4d60fedc0 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 21 Aug 2019 07:02:02 +0200 Subject: Code cleanup in ssa/bytecode. Remove ugly memcpy --- src/std/buffer.c | 7 +++++-- src/std/hash_map.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/std') diff --git a/src/std/buffer.c b/src/std/buffer.c index 93e8558..a482bb9 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -37,9 +37,12 @@ static CHECK_RESULT int buffer_ensure_capacity(Buffer *self, usize new_capacity) if(capacity == 0) { capacity = new_capacity; } else { - while(capacity < new_capacity) { - capacity *= 1.5; + double cap = capacity; + const double new_cap = new_capacity; + while(cap < new_cap) { + cap *= 1.5; } + capacity = cap; } alloc_result = am_realloc(self->data, capacity, &new_mem); diff --git a/src/std/hash_map.c b/src/std/hash_map.c index 48e9e38..98ebf40 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -85,6 +85,7 @@ int hash_map_init(HashMap *self, ArenaAllocator *allocator, usize value_type_siz return_if_error(buffer_init(&self->buckets, self->allocator)); assert(self->buckets.size == 0); return_if_error(buffer_append_empty(&self->buckets, sizeof(HashMapBucket) * HASH_MAP_INITIAL_SIZE)); + assert(HASH_MAP_INITIAL_SIZE != 0); am_memset(self->buckets.data, 0, self->buckets.size); return 0; } -- cgit v1.2.3