From 7984ea4eb61ebeb0dfed6672c9003d7e458e09d6 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 29 Jan 2020 10:47:09 +0100 Subject: [PATCH] tweaks: remove two superfluous assignments, and rename a variable The 'prev' and 'next' links get assigned to immediately after the call of copy_node(). And anyway, it does not make sense to link a copied node to the predecessor and successor of its original. Also slightly regroup some lines. --- src/nano.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/nano.c b/src/nano.c index 6240885b..774cf1a3 100644 --- a/src/nano.c +++ b/src/nano.c @@ -101,10 +101,7 @@ linestruct *copy_node(const linestruct *src) linestruct *dst = nmalloc(sizeof(linestruct)); dst->data = copy_of(src->data); - dst->next = src->next; - dst->prev = src->prev; dst->lineno = src->lineno; - #ifdef ENABLE_COLOR dst->multidata = NULL; #endif @@ -159,22 +156,23 @@ void delete_node(linestruct *line) /* Duplicate an entire linked list of linestructs. */ linestruct *copy_buffer(const linestruct *src) { - linestruct *head, *copy; + linestruct *head, *item; - copy = copy_node(src); - copy->prev = NULL; - head = copy; + head = copy_node(src); + head->prev = NULL; + + item = head; src = src->next; while (src != NULL) { - copy->next = copy_node(src); - copy->next->prev = copy; - copy = copy->next; + item->next = copy_node(src); + item->next->prev = item; + item = item->next; src = src->next; } - copy->next = NULL; + item->next = NULL; return head; }