tweaks: elide two functions that each were called just once

This also gets rid of an assignment in an 'if' clause (twice),
elides a local variable, and makes it clearer that a pointer
gets moved to the previous or next item (instead of hiding it
as a side effect of the function call).
This commit is contained in:
Benno Schulenberg 2021-10-09 17:15:14 +02:00
parent 65d81c60cd
commit 87cde1590d
3 changed files with 6 additions and 32 deletions

View File

@ -145,30 +145,6 @@ void update_history(linestruct **item, const char *text)
*item = *hbot;
}
/* Move h to the string in the history list just before it, and return
* that string. If there isn't one, don't move h and return NULL. */
char *get_history_older(linestruct **h)
{
if ((*h)->prev == NULL)
return NULL;
*h = (*h)->prev;
return (*h)->data;
}
/* Move h to the string in the history list just after it, and return
* that string. If there isn't one, don't move h and return NULL. */
char *get_history_newer(linestruct **h)
{
if ((*h)->next == NULL)
return NULL;
*h = (*h)->next;
return (*h)->data;
}
/* Two empty placeholder functions. */
void get_history_older_void(void)
{

View File

@ -446,8 +446,6 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
bool finished;
functionptrtype func;
#ifdef ENABLE_HISTORIES
char *history = NULL;
/* The current history string. */
char *magichistory = NULL;
/* The (partial) answer that was typed at the prompt, if any. */
#ifdef ENABLE_TABCOMP
@ -515,8 +513,9 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
/* Get the older search from the history list and save it in
* answer. If there is no older search, don't do anything. */
if ((history = get_history_older(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
if ((*history_list)->prev != NULL) {
*history_list = (*history_list)->prev;
answer = mallocstrcpy(answer, (*history_list)->data);
typing_x = strlen(answer);
}
}
@ -524,8 +523,9 @@ functionptrtype acquire_an_answer(int *actual, bool *listed,
if (history_list != NULL) {
/* Get the newer search from the history list and save it in
* answer. If there is no newer search, don't do anything. */
if ((history = get_history_newer(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
if ((*history_list)->next != NULL) {
*history_list = (*history_list)->next;
answer = mallocstrcpy(answer, (*history_list)->data);
typing_x = strlen(answer);
}

View File

@ -336,8 +336,6 @@ void do_help(void);
void history_init(void);
void history_reset(const linestruct *list);
void update_history(linestruct **item, const char *text);
char *get_history_older(linestruct **h);
char *get_history_newer(linestruct **h);
void get_history_older_void(void);
void get_history_newer_void(void);
#ifdef ENABLE_TABCOMP