mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
736c36c02f
commit
b433acc3c9
@ -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))
|
||||
@ -166,7 +169,6 @@ void init_history(void)
|
||||
}
|
||||
hislen = newlen;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void hist_free_entry(histentry_T *hisptr)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
@ -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]) {
|
||||
@ -232,8 +237,6 @@ static int in_history(int type, char *str, int move_to_front, int sep)
|
||||
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;
|
||||
}
|
||||
@ -323,7 +330,6 @@ void add_to_history(int histype, char *new_entry, int in_map, int sep)
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user