mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(completion): use an inline function to free cptext (#26380)
This commit is contained in:
parent
5651c1ff27
commit
589f4761ee
@ -747,6 +747,16 @@ int ins_compl_add_infercase(char *str_arg, int len, bool icase, char *fname, Dir
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// free cptext
|
||||||
|
static inline void free_cptext(char *const *const cptext)
|
||||||
|
{
|
||||||
|
if (cptext != NULL) {
|
||||||
|
for (size_t i = 0; i < CPT_COUNT; i++) {
|
||||||
|
xfree(cptext[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a match to the list of matches
|
/// Add a match to the list of matches
|
||||||
///
|
///
|
||||||
/// @param[in] str text of the match to add
|
/// @param[in] str text of the match to add
|
||||||
@ -784,16 +794,10 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
|
|||||||
} else {
|
} else {
|
||||||
os_breakcheck();
|
os_breakcheck();
|
||||||
}
|
}
|
||||||
#define FREE_CPTEXT(cptext, cptext_allocated) \
|
|
||||||
do { \
|
|
||||||
if ((cptext) != NULL && (cptext_allocated)) { \
|
|
||||||
for (size_t i = 0; i < CPT_COUNT; i++) { \
|
|
||||||
xfree((cptext)[i]); \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
if (got_int) {
|
if (got_int) {
|
||||||
FREE_CPTEXT(cptext, cptext_allocated);
|
if (cptext_allocated) {
|
||||||
|
free_cptext(cptext);
|
||||||
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@ -807,7 +811,9 @@ static int ins_compl_add(char *const str, int len, char *const fname, char *cons
|
|||||||
if (!match_at_original_text(match)
|
if (!match_at_original_text(match)
|
||||||
&& strncmp(match->cp_str, str, (size_t)len) == 0
|
&& strncmp(match->cp_str, str, (size_t)len) == 0
|
||||||
&& ((int)strlen(match->cp_str) <= len || match->cp_str[len] == NUL)) {
|
&& ((int)strlen(match->cp_str) <= len || match->cp_str[len] == NUL)) {
|
||||||
FREE_CPTEXT(cptext, cptext_allocated);
|
if (cptext_allocated) {
|
||||||
|
free_cptext(cptext);
|
||||||
|
}
|
||||||
return NOTDONE;
|
return NOTDONE;
|
||||||
}
|
}
|
||||||
match = match->cp_next;
|
match = match->cp_next;
|
||||||
@ -1552,9 +1558,7 @@ static void ins_compl_free(void)
|
|||||||
if (match->cp_flags & CP_FREE_FNAME) {
|
if (match->cp_flags & CP_FREE_FNAME) {
|
||||||
xfree(match->cp_fname);
|
xfree(match->cp_fname);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < CPT_COUNT; i++) {
|
free_cptext(match->cp_text);
|
||||||
xfree(match->cp_text[i]);
|
|
||||||
}
|
|
||||||
tv_clear(&match->cp_user_data);
|
tv_clear(&match->cp_user_data);
|
||||||
xfree(match);
|
xfree(match);
|
||||||
} while (compl_curr_match != NULL && !is_first_match(compl_curr_match));
|
} while (compl_curr_match != NULL && !is_first_match(compl_curr_match));
|
||||||
@ -2459,9 +2463,7 @@ static int ins_compl_add_tv(typval_T *const tv, const Direction dir, bool fast)
|
|||||||
CLEAR_FIELD(cptext);
|
CLEAR_FIELD(cptext);
|
||||||
}
|
}
|
||||||
if (word == NULL || (!empty && *word == NUL)) {
|
if (word == NULL || (!empty && *word == NUL)) {
|
||||||
for (size_t i = 0; i < CPT_COUNT; i++) {
|
free_cptext(cptext);
|
||||||
xfree(cptext[i]);
|
|
||||||
}
|
|
||||||
tv_clear(&user_data);
|
tv_clear(&user_data);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user