aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/garray.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/garray.h')
-rw-r--r--src/nvim/garray.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/nvim/garray.h b/src/nvim/garray.h
index 6e440039dd..5a90da21c2 100644
--- a/src/nvim/garray.h
+++ b/src/nvim/garray.h
@@ -1,6 +1,8 @@
#ifndef NVIM_GARRAY_H
#define NVIM_GARRAY_H
+#include "nvim/log.h"
+
/// Structure used for growing arrays.
/// This is used to store information that only grows, is deleted all at
/// once, and needs to be accessed by index. See ga_clear() and ga_grow().
@@ -12,11 +14,30 @@ typedef struct growarray {
void *ga_data; // pointer to the first item
} garray_T;
-#define GA_EMPTY_INIT_VALUE { 0, 0, 0, 0, NULL }
+#define GA_EMPTY_INIT_VALUE { 0, 0, 0, 1, NULL }
#define GA_EMPTY(ga_ptr) ((ga_ptr)->ga_len <= 0)
+#define GA_APPEND(item_type, gap, item) \
+ do { \
+ ga_grow(gap, 1); \
+ ((item_type *)(gap)->ga_data)[(gap)->ga_len++] = (item); \
+ } while (0)
+
+#define GA_APPEND_VIA_PTR(item_type, gap) \
+ ga_append_via_ptr(gap, sizeof(item_type))
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "garray.h.generated.h"
#endif
+
+static inline void *ga_append_via_ptr(garray_T *gap, size_t item_size)
+{
+ if ((int)item_size != gap->ga_itemsize) {
+ ELOG("wrong item size in garray(%d), should be %d", item_size);
+ }
+ ga_grow(gap, 1);
+ return ((char *)gap->ga_data) + (item_size * (size_t)gap->ga_len++);
+}
+
#endif // NVIM_GARRAY_H