summaryrefslogtreecommitdiff
path: root/src/spellfile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-04-02 18:50:46 +0200
committerBram Moolenaar <Bram@vim.org>2020-04-02 18:50:46 +0200
commitaeea72151c31d686bcbb7b06d895006d7363585c (patch)
tree500d487503a1a82cecc8f2a3e9bf89b50638fe5a /src/spellfile.c
parentf10806b25090879fdc1a86cc0da2f4f34fd21921 (diff)
downloadvim-git-aeea72151c31d686bcbb7b06d895006d7363585c.tar.gz
patch 8.2.0500: using the same loop in many placesv8.2.0500
Problem: Using the same loop in many places. Solution: Define more FOR_ALL macros. (Yegappan Lakshmanan, closes #5339)
Diffstat (limited to 'src/spellfile.c')
-rw-r--r--src/spellfile.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/spellfile.c b/src/spellfile.c
index 9500813e0..920e05194 100644
--- a/src/spellfile.c
+++ b/src/spellfile.c
@@ -296,6 +296,12 @@
#define CF_WORD 0x01
#define CF_UPPER 0x02
+/*
+ * Loop through all the siblings of a node (including the node)
+ */
+#define FOR_ALL_NODE_SIBLINGS(node, np) \
+ for ((np) = (node); (np) != NULL; (np) = (np)->wn_sibling)
+
static int set_spell_finish(spelltab_T *new_st);
static int write_spell_prefcond(FILE *fd, garray_T *gap);
static int read_region_section(FILE *fd, slang_T *slang, int len);
@@ -1737,7 +1743,7 @@ spell_reload_one(
slang_T *slang;
int didit = FALSE;
- for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+ FOR_ALL_SPELL_LANGS(slang)
{
if (fullpathcmp(fname, slang->sl_fname, FALSE, TRUE) == FPC_SAME)
{
@@ -2081,7 +2087,7 @@ spell_clear_flags(wordnode_T *node)
{
wordnode_T *np;
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
{
np->wn_u1.index = FALSE;
spell_clear_flags(np->wn_child);
@@ -4427,7 +4433,7 @@ tree_add_word(
{
--node->wn_refs;
copyprev = prev;
- for (copyp = node; copyp != NULL; copyp = copyp->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, copyp)
{
// Allocate a new node and copy the info.
np = get_wordnode(spin);
@@ -4618,7 +4624,7 @@ deref_wordnode(spellinfo_T *spin, wordnode_T *node)
if (--node->wn_refs == 0)
{
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
{
if (np->wn_child != NULL)
cnt += deref_wordnode(spin, np->wn_child);
@@ -4761,7 +4767,7 @@ node_compress(
*/
node->wn_u1.hashkey[0] = len;
nr = 0;
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
{
if (np->wn_byte == NUL)
// end node: use wn_flags, wn_region and wn_affixID
@@ -5252,7 +5258,7 @@ clear_node(wordnode_T *node)
wordnode_T *np;
if (node != NULL)
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
{
np->wn_u1.index = 0;
np->wn_u2.wnode = NULL;
@@ -5296,7 +5302,7 @@ put_node(
node->wn_u1.index = idx;
// Count the number of siblings.
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
++siblingcount;
// Write the sibling count.
@@ -5304,7 +5310,7 @@ put_node(
putc(siblingcount, fd); // <siblingcount>
// Write each sibling byte and optionally extra info.
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
{
if (np->wn_byte == 0)
{
@@ -5392,7 +5398,7 @@ put_node(
newindex += siblingcount + 1;
// Recursively dump the children of each sibling.
- for (np = node; np != NULL; np = np->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, np)
if (np->wn_byte != 0 && np->wn_child->wn_u2.wnode == node)
newindex = put_node(fd, np->wn_child, newindex, regionmask,
prefixtree);
@@ -5447,7 +5453,7 @@ spell_make_sugfile(spellinfo_T *spin, char_u *wfname)
* of the code for the soundfolding stuff.
* It might have been done already by spell_reload_one().
*/
- for (slang = first_lang; slang != NULL; slang = slang->sl_next)
+ FOR_ALL_SPELL_LANGS(slang)
if (fullpathcmp(wfname, slang->sl_fname, FALSE, TRUE) == FPC_SAME)
break;
if (slang == NULL)
@@ -5666,7 +5672,7 @@ sug_filltable(
int nr;
int prev_nr;
- for (p = node; p != NULL; p = p->wn_sibling)
+ FOR_ALL_NODE_SIBLINGS(node, p)
{
if (p->wn_byte == NUL)
{