diff options
Diffstat (limited to 'src/klib/kvec.h')
-rw-r--r-- | src/klib/kvec.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/klib/kvec.h b/src/klib/kvec.h index a32b35a14c..1b9e6fd9f8 100644 --- a/src/klib/kvec.h +++ b/src/klib/kvec.h @@ -153,6 +153,12 @@ type init_array[INIT_SIZE]; \ } +#define KVI_INITIAL_VALUE(v) { \ + .size = 0, \ + .capacity = ARRAY_SIZE((v).init_array), \ + .items = (v).init_array \ +} + /// Initialize vector with preallocated array /// /// @param[out] v Vector to initialize. @@ -218,6 +224,17 @@ static inline void *_memcpy_free(void *const restrict dest, void *const restrict } \ } while (0) +#define kvi_concat_len(v, data, len) \ + if (len > 0) { \ + kvi_ensure_more_space(v, len); \ + assert((v).items); \ + memcpy((v).items + (v).size, data, sizeof((v).items[0]) * len); \ + (v).size = (v).size + len; \ + } + +#define kvi_concat(v, str) kvi_concat_len(v, str, strlen(str)) +#define kvi_splice(v1, v0) kvi_concat_len(v1, (v0).items, (v0).size) + /// Get location where to store new element to a vector with preallocated array /// /// @param[in,out] v Vector to push to. |