mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
Use GA_DEEP_CLEAR where appropriate
This commit is contained in:
@@ -5420,20 +5420,12 @@ static int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int
|
||||
{
|
||||
garray_T join_ga;
|
||||
int retval;
|
||||
join_T *p;
|
||||
|
||||
ga_init(&join_ga, (int)sizeof(join_T), l->lv_len);
|
||||
retval = list_join_inner(gap, l, sep, echo_style, copyID, &join_ga);
|
||||
|
||||
/* Dispose each item in join_ga. */
|
||||
if (join_ga.ga_data != NULL) {
|
||||
p = (join_T *)join_ga.ga_data;
|
||||
for (int i = 0; i < join_ga.ga_len; ++i) {
|
||||
free(p->tofree);
|
||||
++p;
|
||||
}
|
||||
ga_clear(&join_ga);
|
||||
}
|
||||
# define FREE_JOIN_TOFREE(join) free((join)->tofree)
|
||||
GA_DEEP_CLEAR(&join_ga, join_T, FREE_JOIN_TOFREE);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@@ -2580,13 +2580,11 @@ char_u *get_scriptname(scid_T id)
|
||||
}
|
||||
|
||||
# if defined(EXITFREE) || defined(PROTO)
|
||||
void free_scriptnames(void)
|
||||
void free_scriptnames()
|
||||
{
|
||||
for (int i = script_items.ga_len; i > 0; --i)
|
||||
free(SCRIPT_ITEM(i).sn_name);
|
||||
ga_clear(&script_items);
|
||||
# define FREE_SCRIPTNAME(item) free((item)->sn_name)
|
||||
GA_DEEP_CLEAR(&script_items, scriptitem_T, FREE_SCRIPTNAME);
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
|
||||
|
@@ -4535,20 +4535,18 @@ void ex_comclear(exarg_T *eap)
|
||||
uc_clear(&curbuf->b_ucmds);
|
||||
}
|
||||
|
||||
static void free_ucmd(ucmd_T* cmd) {
|
||||
free(cmd->uc_name);
|
||||
free(cmd->uc_rep);
|
||||
free(cmd->uc_compl_arg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear all user commands for "gap".
|
||||
*/
|
||||
void uc_clear(garray_T *gap)
|
||||
{
|
||||
ucmd_T *cmd;
|
||||
|
||||
for (int i = 0; i < gap->ga_len; ++i) {
|
||||
cmd = USER_CMD_GA(gap, i);
|
||||
free(cmd->uc_name);
|
||||
free(cmd->uc_rep);
|
||||
free(cmd->uc_compl_arg);
|
||||
}
|
||||
ga_clear(gap);
|
||||
GA_DEEP_CLEAR(gap, ucmd_T, free_ucmd);
|
||||
}
|
||||
|
||||
static void ex_delcommand(exarg_T *eap)
|
||||
@@ -5477,9 +5475,8 @@ static void ex_goto(exarg_T *eap)
|
||||
*/
|
||||
void alist_clear(alist_T *al)
|
||||
{
|
||||
while (--al->al_ga.ga_len >= 0)
|
||||
free(AARGLIST(al)[al->al_ga.ga_len].ae_fname);
|
||||
ga_clear(&al->al_ga);
|
||||
# define FREE_AENTRY_FNAME(arg) free(arg->ae_fname)
|
||||
GA_DEEP_CLEAR(&al->al_ga, aentry_T, FREE_AENTRY_FNAME);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1336,9 +1336,8 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
|
||||
*/
|
||||
void deleteFoldRecurse(garray_T *gap)
|
||||
{
|
||||
for (int i = 0; i < gap->ga_len; ++i)
|
||||
deleteFoldRecurse(&(((fold_T *)(gap->ga_data))[i].fd_nested));
|
||||
ga_clear(gap);
|
||||
# define DELETE_FOLD_NESTED(fd) deleteFoldRecurse(&((fd)->fd_nested))
|
||||
GA_DEEP_CLEAR(gap, fold_T, DELETE_FOLD_NESTED);
|
||||
}
|
||||
|
||||
/* foldMarkAdjust() {{{2 */
|
||||
|
@@ -1424,6 +1424,12 @@ typedef struct {
|
||||
|
||||
static garray_T menutrans_ga = GA_EMPTY_INIT_VALUE;
|
||||
|
||||
#define FREE_MENUTRANS(mt) \
|
||||
menutrans_T* _mt = (mt); \
|
||||
free(_mt->from); \
|
||||
free(_mt->from_noamp); \
|
||||
free(_mt->to)
|
||||
|
||||
/*
|
||||
* ":menutrans".
|
||||
* This function is also defined without the +multi_lang feature, in which
|
||||
@@ -1441,13 +1447,8 @@ void ex_menutranslate(exarg_T *eap)
|
||||
* ":menutrans clear": clear all translations.
|
||||
*/
|
||||
if (STRNCMP(arg, "clear", 5) == 0 && ends_excmd(*skipwhite(arg + 5))) {
|
||||
menutrans_T *tp = (menutrans_T *)menutrans_ga.ga_data;
|
||||
for (int i = 0; i < menutrans_ga.ga_len; ++i) {
|
||||
free(tp[i].from);
|
||||
free(tp[i].from_noamp);
|
||||
free(tp[i].to);
|
||||
}
|
||||
ga_clear(&menutrans_ga);
|
||||
GA_DEEP_CLEAR(&menutrans_ga, menutrans_T, FREE_MENUTRANS);
|
||||
|
||||
/* Delete all "menutrans_" global variables. */
|
||||
del_menutrans_vars();
|
||||
} else {
|
||||
|
@@ -9200,15 +9200,10 @@ static void tree_count_words(char_u *byts, idx_T *idxs)
|
||||
// Free the info put in "*su" by spell_find_suggest().
|
||||
static void spell_find_cleanup(suginfo_T *su)
|
||||
{
|
||||
# define FREE_SUG_WORD(sug) free(sug->st_word)
|
||||
// Free the suggestions.
|
||||
for (int i = 0; i < su->su_ga.ga_len; ++i) {
|
||||
free(SUG(su->su_ga, i).st_word);
|
||||
}
|
||||
ga_clear(&su->su_ga);
|
||||
for (int i = 0; i < su->su_sga.ga_len; ++i) {
|
||||
free(SUG(su->su_sga, i).st_word);
|
||||
}
|
||||
ga_clear(&su->su_sga);
|
||||
GA_DEEP_CLEAR(&su->su_ga, suggest_T, FREE_SUG_WORD);
|
||||
GA_DEEP_CLEAR(&su->su_sga, suggest_T, FREE_SUG_WORD);
|
||||
|
||||
// Free the banned words.
|
||||
hash_clear_all(&su->su_banned, 0);
|
||||
|
@@ -550,14 +550,9 @@ void syntax_start(win_T *wp, linenr_T lnum)
|
||||
*/
|
||||
static void clear_syn_state(synstate_T *p)
|
||||
{
|
||||
garray_T *gap;
|
||||
|
||||
if (p->sst_stacksize > SST_FIX_STATES) {
|
||||
gap = &(p->sst_union.sst_ga);
|
||||
for (int i = 0; i < gap->ga_len; i++) {
|
||||
unref_extmatch(SYN_STATE_P(gap)[i].bs_extmatch);
|
||||
}
|
||||
ga_clear(gap);
|
||||
# define UNREF_BUFSTATE_EXTMATCH(bs) unref_extmatch((bs)->bs_extmatch)
|
||||
GA_DEEP_CLEAR(&(p->sst_union.sst_ga), bufstate_T, UNREF_BUFSTATE_EXTMATCH);
|
||||
} else {
|
||||
for (int i = 0; i < p->sst_stacksize; i++) {
|
||||
unref_extmatch(p->sst_union.sst_stack[i].bs_extmatch);
|
||||
@@ -570,11 +565,8 @@ static void clear_syn_state(synstate_T *p)
|
||||
*/
|
||||
static void clear_current_state(void)
|
||||
{
|
||||
stateitem_T *sip = (stateitem_T *)(current_state.ga_data);
|
||||
for (int i = 0; i < current_state.ga_len; i++) {
|
||||
unref_extmatch(sip[i].si_extmatch);
|
||||
}
|
||||
ga_clear(¤t_state);
|
||||
# define UNREF_STATEITEM_EXTMATCH(si) unref_extmatch((si)->si_extmatch)
|
||||
GA_DEEP_CLEAR(¤t_state, stateitem_T, UNREF_STATEITEM_EXTMATCH);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user