diff options
author | comex | 2015-03-01 13:20:08 -0500 |
---|---|---|
committer | comex | 2015-03-01 13:20:08 -0500 |
commit | 471eb472dbd3462b6a5ab21f85621e16c411709b (patch) | |
tree | 1e682ade28b4a49ab8894a19c5205b59d1e73cc9 /lib/cbit/vec.c | |
parent | Add extra argument to substitute_hook_functions and interpose_imports for use... (diff) | |
download | substitute-471eb472dbd3462b6a5ab21f85621e16c411709b.tar.gz |
add vec
Diffstat (limited to '')
-rw-r--r-- | lib/cbit/vec.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/cbit/vec.c b/lib/cbit/vec.c new file mode 100644 index 0000000..21038a2 --- /dev/null +++ b/lib/cbit/vec.c @@ -0,0 +1,23 @@ +#include "cbit/vec.h" +#include <stdio.h> + +void vec_realloc_internal(struct vec_internal *vi, size_t new_capacity, + size_t esize) { + size_t new_size = safe_mul(new_capacity, esize); + if (vi->els == vi->storage) { + void *new = malloc(new_size); + memcpy(new, vi->els, vi->capacity * esize); + vi->els = new; + } else { + vi->els = realloc(vi->els, new_size); + } + vi->capacity = new_capacity; +} +void vec_realloc_internal_as_necessary(struct vec_internal *vi, + size_t min_capacity, + size_t esize) { + if (min_capacity > vi->capacity) + vec_realloc_internal(vi, safe_mul(vi->capacity, 2), esize); + else if (min_capacity < vi->capacity / 3) + vec_realloc_internal(vi, vi->capacity / 3, esize); +} |