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

View File

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