vim-patch:9.0.0872: code is indented more than needed (#21046)

Problem:    Code is indented more than needed.
Solution:   Return early. (Yegappan Lakshmanan, closes vim/vim#11538)

623e94e138

Only port the first change to init_history() as Nvim has refactored it.

Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
zeertzjq 2022-11-14 07:16:42 +08:00 committed by GitHub
parent 736c36c02f
commit b433acc3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,10 +116,13 @@ void init_history(void)
int newlen = (int)p_hi;
int oldlen = hislen;
if (newlen == oldlen) { // history length didn't change
return;
}
// If history tables size changed, reallocate them.
// Tables are circular arrays (current position marked by hisidx[type]).
// On copying them to the new arrays, we take the chance to reorder them.
if (newlen != oldlen) {
for (int type = 0; type < HIST_COUNT; type++) {
histentry_T *temp = (newlen
? xmalloc((size_t)newlen * sizeof(*temp))
@ -165,7 +168,6 @@ void init_history(void)
history[type] = temp;
}
hislen = newlen;
}
}
static inline void hist_free_entry(histentry_T *hisptr)
@ -215,7 +217,10 @@ static int in_history(int type, char *str, int move_to_front, int sep)
}
} while (i != hisidx[type]);
if (last_i >= 0) {
if (last_i < 0) {
return false;
}
list_T *const list = history[type][i].additional_elements;
str = history[type][i].hisstr;
while (i != hisidx[type]) {
@ -231,8 +236,6 @@ static int in_history(int type, char *str, int move_to_front, int sep)
history[type][i].timestamp = os_time();
history[type][i].additional_elements = NULL;
return true;
}
return false;
}
/// Convert history name to its HIST_ equivalent
@ -304,7 +307,11 @@ void add_to_history(int histype, char *new_entry, int in_map, int sep)
}
last_maptick = -1;
}
if (!in_history(histype, new_entry, true, sep)) {
if (in_history(histype, new_entry, true, sep)) {
return;
}
if (++hisidx[histype] == hislen) {
hisidx[histype] = 0;
}
@ -322,7 +329,6 @@ void add_to_history(int histype, char *new_entry, int in_map, int sep)
if (histype == HIST_SEARCH && in_map) {
last_maptick = maptick;
}
}
}
/// Get identifier of newest history entry.
@ -504,16 +510,19 @@ void f_histadd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
const char *str = tv_get_string_chk(&argvars[0]); // NULL on type error
histype = str != NULL ? get_histtype(str, strlen(str), false) : HIST_INVALID;
if (histype != HIST_INVALID) {
if (histype == HIST_INVALID) {
return;
}
char buf[NUMBUFLEN];
str = tv_get_string_buf(&argvars[1], buf);
if (*str != NUL) {
if (*str == NUL) {
return;
}
init_history();
add_to_history(histype, (char *)str, false, NUL);
rettv->vval.v_number = true;
return;
}
}
}
/// "histdel()" function