diff src/syntax.c @ 19934:3ff714d765ba v8.2.0523

patch 8.2.0523: loops are repeated Commit: https://github.com/vim/vim/commit/00d253e2b2f435a5386582c3f857008e7ac355c2 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 6 22:13:01 2020 +0200 patch 8.2.0523: loops are repeated Problem: Loops are repeated. Solution: Use FOR_ALL_ macros. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5882)
author Bram Moolenaar <Bram@vim.org>
date Mon, 06 Apr 2020 22:15:39 +0200
parents 5feb426d2ea1
children aadd1cae2ff5
line wrap: on
line diff
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -256,6 +256,9 @@ static reg_extmatch_T *next_match_extmat
 #define INVALID_STATE(ssp)  ((ssp)->ga_itemsize == 0)
 #define VALID_STATE(ssp)    ((ssp)->ga_itemsize != 0)
 
+#define FOR_ALL_SYNSTATES(sb, sst) \
+    for ((sst) = (sb)->b_sst_first; (sst) != NULL; (sst) = (sst)->sst_next)
+
 /*
  * The current state (within the line) of the recognition engine.
  * When current_state.ga_itemsize is 0 the current state is invalid.
@@ -438,7 +441,7 @@ syntax_start(win_T *wp, linenr_T lnum)
     if (INVALID_STATE(&current_state) && syn_block->b_sst_array != NULL)
     {
 	// Find last valid saved state before start_lnum.
-	for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next)
+	FOR_ALL_SYNSTATES(syn_block, p)
 	{
 	    if (p->sst_lnum > lnum)
 		break;
@@ -1044,7 +1047,7 @@ syn_stack_free_block(synblock_T *block)
 
     if (block->b_sst_array != NULL)
     {
-	for (p = block->b_sst_first; p != NULL; p = p->sst_next)
+	FOR_ALL_SYNSTATES(block, p)
 	    clear_syn_state(p);
 	VIM_CLEAR(block->b_sst_array);
 	block->b_sst_first = NULL;
@@ -1353,7 +1356,7 @@ store_current_state(void)
 	    else
 	    {
 		// find the entry just before this one to adjust sst_next
-		for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next)
+		FOR_ALL_SYNSTATES(syn_block, p)
 		    if (p->sst_next == sp)
 			break;
 		if (p != NULL)	// just in case