aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/hashtab.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/hashtab.h')
-rw-r--r--src/nvim/hashtab.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nvim/hashtab.h b/src/nvim/hashtab.h
index 0da2b13f2e..973b97d476 100644
--- a/src/nvim/hashtab.h
+++ b/src/nvim/hashtab.h
@@ -70,6 +70,25 @@ typedef struct hashtable_S {
hashitem_T ht_smallarray[HT_INIT_SIZE]; /// initial array
} hashtab_T;
+/// Iterate over a hashtab
+///
+/// @param[in] ht Hashtab to iterate over.
+/// @param hi Name of the variable with current hashtab entry.
+/// @param code Cycle body.
+#define HASHTAB_ITER(ht, hi, code) \
+ do { \
+ hashtab_T *const hi##ht_ = (ht); \
+ size_t hi##todo_ = hi##ht_->ht_used; \
+ for (hashitem_T *hi = hi##ht_->ht_array; hi##todo_; hi++) { \
+ if (!HASHITEM_EMPTY(hi)) { \
+ { \
+ code \
+ } \
+ hi##todo_--; \
+ } \
+ } \
+ } while (0)
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "hashtab.h.generated.h"
#endif