commit 87cde1590d0b6f582203466e98b83d6aa2a4a307
parent 65d81c60cd23d4c82fd0ae174b5673db94a2f0d8
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 9 Oct 2021 17:15:14 +0200
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).
Diffstat:
3 files changed, 6 insertions(+), 32 deletions(-)
diff --git a/src/history.c b/src/history.c
@@ -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)
{
diff --git a/src/prompt.c b/src/prompt.c
@@ -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);
}
diff --git a/src/prototypes.h b/src/prototypes.h
@@ -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