diff --git a/ChangeLog b/ChangeLog index 700832c0..8078c058 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * src/browser.c (do_browser): Plug a memory leak by not copying a string twice. This fixes Savannah bug #47206. * src/browser.c (do_browser): Now put things in the proper order. + * src/files.c (make_new_buffer), src/nano.c (splice_opennode): Elide + the latter function, by handling the two cases (the creation of the + first element, and the insertion of a new element) directly. 2016-02-23 Benno Schulenberg * src/prompt.c (do_statusbar_output, do_statusbar_delete): diff --git a/src/files.c b/src/files.c index b5a177f0..0b226f68 100644 --- a/src/files.c +++ b/src/files.c @@ -71,17 +71,25 @@ bool has_valid_path(const char *filename) * called from open_buffer(). */ void make_new_buffer(void) { - /* If there are no entries in openfile, make the first one and - * move to it. */ if (openfile == NULL) { openfile = make_new_opennode(); - splice_opennode(openfile, openfile, openfile); - /* Otherwise, make a new entry for openfile, splice it in after - * the current entry, and move to it. */ + + /* Make the first open file the only element in a circular list. */ + openfile->prev = openfile; + openfile->next = openfile; } else { - splice_opennode(openfile, make_new_opennode(), openfile->next); - openfile = openfile->next; - /* More than one file open, show Close in help lines. */ + openfilestruct *newnode = make_new_opennode(); + + /* Add the new open file after the current one in the list. */ + newnode->prev = openfile; + newnode->next = openfile->next; + openfile->next->prev = newnode; + openfile->next = newnode; + + /* Make the new file the current one. */ + openfile = newnode; + + /* There is more than one file open: show Close in help lines. */ exitfunc->desc = close_tag; } diff --git a/src/nano.c b/src/nano.c index a5236a73..708e5894 100644 --- a/src/nano.c +++ b/src/nano.c @@ -525,20 +525,6 @@ openfilestruct *make_new_opennode(void) return (openfilestruct *)nmalloc(sizeof(openfilestruct)); } -/* Splice a node into an existing openfilestruct. */ -void splice_opennode(openfilestruct *begin, openfilestruct *newnode, - openfilestruct *end) -{ - assert(newnode != NULL && begin != NULL); - - newnode->next = end; - newnode->prev = begin; - begin->next = newnode; - - if (end != NULL) - end->prev = newnode; -} - /* Unlink a node from the rest of the openfilestruct, and delete it. */ void unlink_opennode(openfilestruct *fileptr) { diff --git a/src/proto.h b/src/proto.h index 48b60518..e370f551 100644 --- a/src/proto.h +++ b/src/proto.h @@ -447,8 +447,6 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot, filestruct *top, size_t top_x, filestruct *bot, size_t bot_x); void copy_from_filestruct(filestruct *somebuffer); openfilestruct *make_new_opennode(void); -void splice_opennode(openfilestruct *begin, openfilestruct *newnode, - openfilestruct *end); void unlink_opennode(openfilestruct *fileptr); void delete_opennode(openfilestruct *fileptr); void print_view_warning(void);