summaryrefslogtreecommitdiffstats
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-22 21:50:18 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-22 21:50:18 +0200
commitdf48fb456fb6bf63d94cad9b302ff01d8ee8d311 (patch)
treee40ac7facad1b205bf5990a535c8c1686fbeb05b /src/list.c
parent36edf0685c8b55ee3ce709058d83ada8027fec1e (diff)
patch 7.4.2090v7.4.2090
Problem: Using submatch() in a lambda passed to substitute() is verbose. Solution: Use a static list and pass it as an optional argument to the function. Fix memory leak.
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/list.c b/src/list.c
index 13f920039c..9e0e26fafd 100644
--- a/src/list.c
+++ b/src/list.c
@@ -924,4 +924,35 @@ write_list(FILE *fd, list_T *list, int binary)
return ret;
}
+/*
+ * Initialize a static list with 10 items.
+ */
+ void
+init_static_list(staticList10_T *sl)
+{
+ list_T *l = &sl->sl_list;
+ int i;
+
+ memset(sl, 0, sizeof(staticList10_T));
+ l->lv_first = &sl->sl_items[0];
+ l->lv_last = &sl->sl_items[9];
+ l->lv_refcount = DO_NOT_FREE_CNT;
+ l->lv_lock = VAR_FIXED;
+ sl->sl_list.lv_len = 10;
+
+ for (i = 0; i < 10; ++i)
+ {
+ listitem_T *li = &sl->sl_items[i];
+
+ if (i == 0)
+ li->li_prev = NULL;
+ else
+ li->li_prev = li - 1;
+ if (i == 9)
+ li->li_next = NULL;
+ else
+ li->li_next = li + 1;
+ }
+}
+
#endif /* defined(FEAT_EVAL) */