aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/ex_cmds2.c2
-rw-r--r--src/nvim/ex_docmd.c4
-rw-r--r--src/nvim/ex_getln.c4
-rw-r--r--src/nvim/fold.c6
-rw-r--r--src/nvim/garray.c2
-rw-r--r--src/nvim/garray.h2
-rw-r--r--src/nvim/hardcopy.c2
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/os/shell.c2
-rw-r--r--src/nvim/path.c2
-rw-r--r--src/nvim/regexp.c2
-rw-r--r--src/nvim/screen.c2
-rw-r--r--src/nvim/spell.c40
-rw-r--r--src/nvim/syntax.c6
15 files changed, 41 insertions, 39 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 499e0a2b5b..cca81e7d94 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -10766,7 +10766,7 @@ static garray_T ga_userinput = {0, 0, sizeof(tasave_T), 4, NULL};
*/
static void f_inputrestore(typval_T *argvars, typval_T *rettv)
{
- if (ga_userinput.ga_len > 0) {
+ if (!GA_EMPTY(&ga_userinput)) {
--ga_userinput.ga_len;
restore_typeahead((tasave_T *)(ga_userinput.ga_data)
+ ga_userinput.ga_len);
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index b616b2de24..33fa7c3f30 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -580,7 +580,7 @@ void ex_breakdel(exarg_T *eap)
if (todel < 0)
EMSG2(_("E161: Breakpoint not found: %s"), eap->arg);
else {
- while (gap->ga_len > 0) {
+ while (!GA_EMPTY(gap)) {
free(DEBUGGY(gap, todel).dbg_name);
vim_regfree(DEBUGGY(gap, todel).dbg_prog);
--gap->ga_len;
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 268e625b48..368d5c9b0c 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -872,7 +872,7 @@ int flags;
* When not inside any ":while" loop, clear remembered lines.
*/
if (cstack.cs_looplevel == 0) {
- if (lines_ga.ga_len > 0) {
+ if (!GA_EMPTY(&lines_ga)) {
sourcing_lnum =
((wcmd_T *)lines_ga.ga_data)[lines_ga.ga_len - 1].lnum;
free_cmdlines(&lines_ga);
@@ -1188,7 +1188,7 @@ static void store_loop_line(garray_T *gap, char_u *line)
*/
static void free_cmdlines(garray_T *gap)
{
- while (gap->ga_len > 0) {
+ while (!GA_EMPTY(gap)) {
free(((wcmd_T *)(gap->ga_data))[gap->ga_len - 1].line);
--gap->ga_len;
}
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index d5410346aa..db9a483040 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1831,7 +1831,7 @@ getexmodeline (
if (c1 == BS || c1 == K_BS
|| c1 == DEL || c1 == K_DEL || c1 == K_KDEL) {
- if (line_ga.ga_len > 0) {
+ if (!GA_EMPTY(&line_ga)) {
--line_ga.ga_len;
goto redraw;
}
@@ -1940,7 +1940,7 @@ redraw:
/* We are done when a NL is entered, but not when it comes after an
* odd number of backslashes, that results in a NUL. */
- if (line_ga.ga_len > 0 && pend[-1] == '\n') {
+ if (!GA_EMPTY(&line_ga) && pend[-1] == '\n') {
int bcount = 0;
while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\')
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index f5801205d7..8320b905b2 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -138,7 +138,7 @@ int hasAnyFolding(win_T *win)
{
/* very simple now, but can become more complex later */
return win->w_p_fen
- && (!foldmethodIsManual(win) || win->w_folds.ga_len > 0);
+ && (!foldmethodIsManual(win) || !GA_EMPTY(&win->w_folds));
}
/* hasFolding() {{{2 */
@@ -2655,7 +2655,7 @@ static void foldMerge(fold_T *fp1, garray_T *gap, fold_T *fp2)
foldMerge(fp3, gap2, fp4);
/* Move nested folds in fp2 to the end of fp1. */
- if (gap2->ga_len > 0) {
+ if (!GA_EMPTY(gap2)) {
ga_grow(gap1, gap2->ga_len);
for (idx = 0; idx < gap2->ga_len; ++idx) {
((fold_T *)gap1->ga_data)[gap1->ga_len]
@@ -2982,7 +2982,7 @@ static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off
fp = (fold_T *)gap->ga_data;
for (i = 0; i < gap->ga_len; i++) {
if (fp->fd_flags != FD_LEVEL) {
- if (fp->fd_nested.ga_len > 0) {
+ if (!GA_EMPTY(&fp->fd_nested)) {
/* open nested folds while this fold is open */
if (fprintf(fd, "%" PRId64, (int64_t)(fp->fd_top + off)) < 0
|| put_eol(fd) == FAIL
diff --git a/src/nvim/garray.c b/src/nvim/garray.c
index 0edd8ed039..79dc2e5797 100644
--- a/src/nvim/garray.c
+++ b/src/nvim/garray.c
@@ -185,7 +185,7 @@ void ga_append(garray_T *gap, char c)
void append_ga_line(garray_T *gap)
{
// Remove trailing CR.
- if ((gap->ga_len > 0)
+ if (!GA_EMPTY(gap)
&& !curbuf->b_p_bin
&& (((char_u *)gap->ga_data)[gap->ga_len - 1] == CAR)) {
gap->ga_len--;
diff --git a/src/nvim/garray.h b/src/nvim/garray.h
index be858dffb0..2b54e56b2b 100644
--- a/src/nvim/garray.h
+++ b/src/nvim/garray.h
@@ -16,6 +16,8 @@ typedef struct growarray {
#define GA_EMPTY_INIT_VALUE { 0, 0, 0, 0, NULL }
+#define GA_EMPTY(ga_ptr) ((ga_ptr)->ga_len <= 0)
+
void ga_clear(garray_T *gap);
void ga_clear_strings(garray_T *gap);
void ga_init(garray_T *gap, int itemsize, int growsize);
diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c
index c0a86a415b..dccc62d9a9 100644
--- a/src/nvim/hardcopy.c
+++ b/src/nvim/hardcopy.c
@@ -1513,7 +1513,7 @@ static void prt_def_var(char *name, double value, int prec)
static void prt_flush_buffer(void)
{
- if (prt_ps_buffer.ga_len > 0) {
+ if (!GA_EMPTY(&prt_ps_buffer)) {
/* Any background color must be drawn first */
if (prt_do_bgcol && (prt_new_bgcol != PRCOLOR_WHITE)) {
int r, g, b;
diff --git a/src/nvim/option.c b/src/nvim/option.c
index c6bd17c04f..c3e561ed4e 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1964,7 +1964,7 @@ void set_init_1(void)
/* First time count the NUL, otherwise count the ','. */
len = (int)STRLEN(p) + 3;
ga_grow(&ga, len);
- if (ga.ga_len > 0)
+ if (!GA_EMPTY(&ga))
STRCAT(ga.ga_data, ",");
STRCAT(ga.ga_data, p);
add_pathsep(ga.ga_data);
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
index bf72811117..8e49f8f2bb 100644
--- a/src/nvim/os/shell.c
+++ b/src/nvim/os/shell.c
@@ -229,7 +229,7 @@ int os_call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
}
if (opts & kShellOptRead) {
- if (pdata.ga.ga_len > 0) {
+ if (!GA_EMPTY(&pdata.ga)) {
// If there's an unfinished line in the growable array, append it now.
append_ga_line(&pdata.ga);
// remember that the NL was missing
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 3d6eacba4c..87c967edbb 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1094,7 +1094,7 @@ gen_expand_wildcards (
free(t);
}
- if (did_expand_in_path && ga.ga_len > 0 && (flags & EW_PATH))
+ if (did_expand_in_path && !GA_EMPTY(&ga) && (flags & EW_PATH))
uniquefy_paths(&ga, p);
if (p != pat[i])
free(p);
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index b724439401..8241770bd3 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -4697,7 +4697,7 @@ regmatch (
* If there is something on the regstack execute the code for the state.
* If the state is popped then loop and use the older state.
*/
- while (regstack.ga_len > 0 && status != RA_FAIL) {
+ while (!GA_EMPTY(&regstack) && status != RA_FAIL) {
rp = (regitem_T *)((char *)regstack.ga_data + regstack.ga_len) - 1;
switch (rp->rs_state) {
case RS_NOPEN:
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 55cc1e23d0..f65fa1066f 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -2380,7 +2380,7 @@ win_line (
if (wp->w_p_spell
&& *wp->w_s->b_p_spl != NUL
- && wp->w_s->b_langp.ga_len > 0
+ && !GA_EMPTY(&wp->w_s->b_langp)
&& *(char **)(wp->w_s->b_langp.ga_data) != NULL) {
/* Prepare for spell checking. */
has_spell = TRUE;
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index e1b290843d..659ea65ac2 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -2324,7 +2324,7 @@ static void slang_clear(slang_T *lp)
for (round = 1; round <= 2; ++round) {
gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal;
- while (gap->ga_len > 0) {
+ while (!GA_EMPTY(gap)) {
ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len];
free(ftp->ft_from);
free(ftp->ft_to);
@@ -2341,7 +2341,7 @@ static void slang_clear(slang_T *lp)
free(((int **)gap->ga_data)[i]);
} else
// SAL items: free salitem_T items
- while (gap->ga_len > 0) {
+ while (!GA_EMPTY(gap)) {
smp = &((salitem_T *)gap->ga_data)[--gap->ga_len];
free(smp->sm_lead);
// Don't free sm_oneof and sm_rules, they point into sm_lead.
@@ -2915,7 +2915,7 @@ static int read_sal_section(FILE *fd, slang_T *slang)
}
}
- if (gap->ga_len > 0) {
+ if (!GA_EMPTY(gap)) {
// Add one extra entry to mark the end with an empty sm_lead. Avoids
// that we need to check the index every time.
smp = &((salitem_T *)gap->ga_data)[gap->ga_len];
@@ -3865,14 +3865,14 @@ char_u *did_set_spelllang(win_T *wp)
lp = LANGP_ENTRY(ga, i);
// sound folding
- if (lp->lp_slang->sl_sal.ga_len > 0)
+ if (!GA_EMPTY(&lp->lp_slang->sl_sal))
// language does sound folding itself
lp->lp_sallang = lp->lp_slang;
else
// find first similar language that does sound folding
for (j = 0; j < ga.ga_len; ++j) {
lp2 = LANGP_ENTRY(ga, j);
- if (lp2->lp_slang->sl_sal.ga_len > 0
+ if (!GA_EMPTY(&lp2->lp_slang->sl_sal)
&& STRNCMP(lp->lp_slang->sl_name,
lp2->lp_slang->sl_name, 2) == 0) {
lp->lp_sallang = lp2->lp_slang;
@@ -3881,14 +3881,14 @@ char_u *did_set_spelllang(win_T *wp)
}
// REP items
- if (lp->lp_slang->sl_rep.ga_len > 0)
+ if (!GA_EMPTY(&lp->lp_slang->sl_rep))
// language has REP items itself
lp->lp_replang = lp->lp_slang;
else
// find first similar language that has REP items
for (j = 0; j < ga.ga_len; ++j) {
lp2 = LANGP_ENTRY(ga, j);
- if (lp2->lp_slang->sl_rep.ga_len > 0
+ if (!GA_EMPTY(&lp2->lp_slang->sl_rep)
&& STRNCMP(lp->lp_slang->sl_name,
lp2->lp_slang->sl_name, 2) == 0) {
lp->lp_replang = lp2->lp_slang;
@@ -5131,7 +5131,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// Check that every character appears only once.
for (p = items[1]; *p != NUL; ) {
c = mb_ptr2char_adv(&p);
- if ((spin->si_map.ga_len > 0
+ if ((!GA_EMPTY(&spin->si_map)
&& vim_strchr(spin->si_map.ga_data, c)
!= NULL)
|| vim_strchr(p, c) != NULL)
@@ -5257,7 +5257,7 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
if (sofofrom == NULL || sofoto == NULL)
smsg((char_u *)_("Missing SOFO%s line in %s"),
sofofrom == NULL ? "FROM" : "TO", fname);
- else if (spin->si_sal.ga_len > 0)
+ else if (!GA_EMPTY(&spin->si_sal))
smsg((char_u *)_("Both SAL and SOFO lines in %s"), fname);
else {
aff_check_string(spin->si_sofofr, sofofrom, "SOFOFROM");
@@ -6909,7 +6909,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
}
// SN_PREFCOND: <prefcondcnt> <prefcond> ...
- if (spin->si_prefcond.ga_len > 0) {
+ if (!GA_EMPTY(&spin->si_prefcond)) {
putc(SN_PREFCOND, fd); // <sectionID>
putc(SNF_REQUIRED, fd); // <sectionflags>
@@ -7037,7 +7037,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// SN_MAP: <mapstr>
// This is for making suggestions, section is not required.
- if (spin->si_map.ga_len > 0) {
+ if (!GA_EMPTY(&spin->si_map)) {
putc(SN_MAP, fd); // <sectionID>
putc(0, fd); // <sectionflags>
l = spin->si_map.ga_len;
@@ -7052,7 +7052,7 @@ static int write_vim_spell(spellinfo_T *spin, char_u *fname)
// with this .spl file. That's because the word numbers must be exactly
// right.
if (!spin->si_nosugfile
- && (spin->si_sal.ga_len > 0
+ && (!GA_EMPTY(&spin->si_sal)
|| (spin->si_sofofr != NULL && spin->si_sofoto != NULL))) {
putc(SN_SUGFILE, fd); // <sectionID>
putc(0, fd); // <sectionflags>
@@ -8151,7 +8151,7 @@ static void init_spellfile(void)
int aspath = FALSE;
char_u *lstart = curbuf->b_s.b_p_spl;
- if (*curwin->w_s->b_p_spl != NUL && curwin->w_s->b_langp.ga_len > 0) {
+ if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) {
buf = alloc(MAXPATHL);
// Find the end of the language name. Exclude the region. If there
@@ -11011,7 +11011,7 @@ static void score_comp_sal(suginfo_T *su)
// Use the sound-folding of the first language that supports it.
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- if (lp->lp_slang->sl_sal.ga_len > 0) {
+ if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
// soundfold the bad word
spell_soundfold(lp->lp_slang, su->su_fbadword, TRUE, badsound);
@@ -11058,7 +11058,7 @@ static void score_combine(suginfo_T *su)
// Add the alternate score to su_ga.
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- if (lp->lp_slang->sl_sal.ga_len > 0) {
+ if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
// soundfold the bad word
slang = lp->lp_slang;
spell_soundfold(slang, su->su_fbadword, TRUE, badsound);
@@ -11216,7 +11216,7 @@ static void suggest_try_soundalike_prep(void)
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
slang = lp->lp_slang;
- if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL)
+ if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL)
// prepare the hashtable used by add_sound_suggest()
hash_init(&slang->sl_sounddone);
}
@@ -11236,7 +11236,7 @@ static void suggest_try_soundalike(suginfo_T *su)
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
slang = lp->lp_slang;
- if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) {
+ if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) {
// soundfold the bad word
spell_soundfold(slang, su->su_fbadword, TRUE, salword);
@@ -11262,7 +11262,7 @@ static void suggest_try_soundalike_finish(void)
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
slang = lp->lp_slang;
- if (slang->sl_sal.ga_len > 0 && slang->sl_sbyts != NULL) {
+ if (!GA_EMPTY(&slang->sl_sal) && slang->sl_sbyts != NULL) {
// Free the info about handled words.
todo = (int)slang->sl_sounddone.ht_used;
for (hi = slang->sl_sounddone.ht_array; todo > 0; ++hi)
@@ -11825,7 +11825,7 @@ static void rescore_one(suginfo_T *su, suggest_T *stp)
// Only rescore suggestions that have no sal score yet and do have a
// language.
- if (slang != NULL && slang->sl_sal.ga_len > 0 && !stp->st_had_bonus) {
+ if (slang != NULL && !GA_EMPTY(&slang->sl_sal) && !stp->st_had_bonus) {
if (slang == su->su_sallang)
p = su->su_sal_badword;
else {
@@ -11899,7 +11899,7 @@ char_u *eval_soundfold(char_u *word)
// Use the sound-folding of the first language that supports it.
for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) {
lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi);
- if (lp->lp_slang->sl_sal.ga_len > 0) {
+ if (!GA_EMPTY(&lp->lp_slang->sl_sal)) {
// soundfold the word
spell_soundfold(lp->lp_slang, word, FALSE, sound);
return vim_strsave(sound);
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index bfe13212ce..6fc62aed9a 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -951,7 +951,7 @@ static void syn_start_line(void)
* Need to update the end of a start/skip/end that continues from the
* previous line and regions that have "keepend".
*/
- if (current_state.ga_len > 0) {
+ if (!GA_EMPTY(&current_state)) {
syn_update_ends(TRUE);
check_state_ends();
}
@@ -2187,7 +2187,7 @@ syn_current_attr (
*/
if (!syncing && !keep_state) {
check_state_ends();
- if (current_state.ga_len > 0
+ if (!GA_EMPTY(&current_state)
&& syn_getcurline()[current_col] != NUL) {
++current_col;
check_state_ends();
@@ -2207,7 +2207,7 @@ syn_current_attr (
&& !(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)))
current_next_list = NULL;
- if (zero_width_next_ga.ga_len > 0)
+ if (!GA_EMPTY(&zero_width_next_ga))
ga_clear(&zero_width_next_ga);
/* No longer need external matches. But keep next_match_extmatch. */