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.
master
Benno Schulenberg 2020-01-29 10:47:09 +01:00
parent f38bd5030d
commit 7984ea4eb6
1 changed files with 9 additions and 11 deletions

View File

@ -101,10 +101,7 @@ linestruct *copy_node(const linestruct *src)
linestruct *dst = nmalloc(sizeof(linestruct)); linestruct *dst = nmalloc(sizeof(linestruct));
dst->data = copy_of(src->data); dst->data = copy_of(src->data);
dst->next = src->next;
dst->prev = src->prev;
dst->lineno = src->lineno; dst->lineno = src->lineno;
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
dst->multidata = NULL; dst->multidata = NULL;
#endif #endif
@ -159,22 +156,23 @@ void delete_node(linestruct *line)
/* Duplicate an entire linked list of linestructs. */ /* Duplicate an entire linked list of linestructs. */
linestruct *copy_buffer(const linestruct *src) linestruct *copy_buffer(const linestruct *src)
{ {
linestruct *head, *copy; linestruct *head, *item;
copy = copy_node(src); head = copy_node(src);
copy->prev = NULL; head->prev = NULL;
head = copy;
item = head;
src = src->next; src = src->next;
while (src != NULL) { while (src != NULL) {
copy->next = copy_node(src); item->next = copy_node(src);
copy->next->prev = copy; item->next->prev = item;
copy = copy->next;
item = item->next;
src = src->next; src = src->next;
} }
copy->next = NULL; item->next = NULL;
return head; return head;
} }