patch 8.2.0500: using the same loop in many places
Problem: Using the same loop in many places.
Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes #5339)
diff --git a/src/terminal.c b/src/terminal.c
index 2ff697a..d7d23cc 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -183,6 +183,9 @@
#define MAX_ROW 999999 // used for tl_dirty_row_end to update all rows
#define KEY_BUF_LEN 200
+#define FOR_ALL_TERMS(term) \
+ for ((term) = first_term; (term) != NULL; (term) = (term)->tl_next)
+
/*
* Functions with separate implementation for MS-Windows and Unix-like systems.
*/
@@ -626,8 +629,7 @@
listitem_T *item;
ga_init2(&ga, 1, 100);
- for (item = argvar->vval.v_list->lv_first;
- item != NULL; item = item->li_next)
+ FOR_ALL_LIST_ITEMS(argvar->vval.v_list, item)
{
char_u *s = tv_get_string_chk(&item->li_tv);
char_u *p;
@@ -1892,7 +1894,7 @@
term_T *term;
int next_due = next_due_arg;
- for (term = first_term; term != NULL; term = term->tl_next)
+ FOR_ALL_TERMS(term)
{
if (term->tl_timer_set && !term->tl_normal_mode)
{
@@ -2175,7 +2177,7 @@
if (l != NULL)
{
type = get_reg_type(c, ®len);
- for (item = l->lv_first; item != NULL; item = item->li_next)
+ FOR_ALL_LIST_ITEMS(l, item)
{
char_u *s = tv_get_string(&item->li_tv);
#ifdef MSWIN
@@ -5701,7 +5703,7 @@
return;
l = rettv->vval.v_list;
- for (tp = first_term; tp != NULL; tp = tp->tl_next)
+ FOR_ALL_TERMS(tp)
if (tp != NULL && tp->tl_buffer != NULL)
if (list_append_number(l,
(varnumber_T)tp->tl_buffer->b_fnum) == FAIL)
@@ -6077,7 +6079,7 @@
{
term_T *term;
- for (term = first_term; term != NULL; term = term->tl_next)
+ FOR_ALL_TERMS(term)
if (term->tl_job == ch->ch_job)
{
if (term->tl_eof_chars != NULL)