From b073d4b0c2c1d4dce36adcc285ad5dfaf2f7599d Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Thu, 27 Jan 2022 03:29:44 +0100 Subject: New list interface for fast tail access --- src/history.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/history.c') diff --git a/src/history.c b/src/history.c index 3c45a67..a0ede46 100644 --- a/src/history.c +++ b/src/history.c @@ -4,11 +4,10 @@ #include #include - void history_init(struct history *history) { - history->list = LIST_HEAD; + list_init(&history->list); history->input = inputln_alloc(); history->sel = history->input; } @@ -41,13 +40,9 @@ history_free(struct history *history) ln = link_pop(LINK(history->input)); inputln_free(UPCAST(ln, struct inputln)); - for (iter = history->list.next; iter; ) { - next = iter->next; - inputln_free(UPCAST(iter, struct inputln)); - iter = next; - } + list_free(&history->list, (link_free_func) inputln_free, + LINK_OFFSET(struct inputln)); - history->list = LIST_HEAD; history->input = NULL; history->sel = NULL; } @@ -102,7 +97,7 @@ history_add(struct history *history, struct inputln *line) if (list_len(&history->list) == HISTORY_MAX) { /* pop last item to make space */ - back = link_pop(link_back(&history->list)); + back = list_pop_back(&history->list); inputln_free(UPCAST(back, struct inputln)); } -- cgit v1.2.3-71-gd317