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/autocmd.c b/src/autocmd.c
index dce23b8..d6945f3 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -235,6 +235,10 @@
static AutoPatCmd *active_apc_list = NULL; // stack of active autocommands
+// Macro to loop over all the patterns for an autocmd event
+#define FOR_ALL_AUTOCMD_PATTERNS(event, ap) \
+ for ((ap) = first_autopat[(int)(event)]; (ap) != NULL; (ap) = (ap)->next)
+
/*
* augroups stores a list of autocmd group names.
*/
@@ -456,7 +460,7 @@
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
event = (event_T)((int)event + 1))
// loop over all autocommand patterns
- for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+ FOR_ALL_AUTOCMD_PATTERNS(event, ap)
if (ap->buflocal_nr == buf->b_fnum)
{
au_remove_pat(ap);
@@ -519,7 +523,7 @@
for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
event = (event_T)((int)event + 1))
{
- for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+ FOR_ALL_AUTOCMD_PATTERNS(event, ap)
if (ap->group == i && ap->pat != NULL)
{
give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
@@ -1041,7 +1045,7 @@
*/
if (*pat == NUL)
{
- for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+ FOR_ALL_AUTOCMD_PATTERNS(event, ap)
{
if (forceit) // delete the AutoPat, if it's in the current group
{
@@ -2400,7 +2404,7 @@
forward_slash(fname);
#endif
- for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
+ FOR_ALL_AUTOCMD_PATTERNS(event, ap)
if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0
? match_file_pat(NULL, &ap->reg_prog,