From f63fee79e35752abc98d537aa520a674c4e9bc4e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 1 Jun 2019 11:10:48 +0200 Subject: [PATCH] tweaks: merge two functions, as the first is called just once --- src/files.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/files.c b/src/files.c index 83aac9ab..e7657564 100644 --- a/src/files.c +++ b/src/files.c @@ -642,31 +642,28 @@ void switch_to_next_buffer(void) redecorate_after_switch(); } -/* Unlink a node from the rest of the circular list, and delete it. */ -void unlink_opennode(openfilestruct *fileptr) -{ - if (fileptr == startfile) - startfile = startfile->next; - - fileptr->prev->next = fileptr->next; - fileptr->next->prev = fileptr->prev; - - free(fileptr->filename); - free_lines(fileptr->filetop); -#ifndef NANO_TINY - free(fileptr->current_stat); - free(fileptr->lock_filename); - /* Free the undo stack. */ - discard_until(NULL, fileptr, TRUE); -#endif - free(fileptr); -} - /* Remove the current buffer from the circular list of buffers. */ void close_buffer(void) { - openfile = openfile->prev; - unlink_opennode(openfile->next); + openfilestruct *orphan = openfile; + + if (orphan == startfile) + startfile = startfile->next; + + orphan->prev->next = orphan->next; + orphan->next->prev = orphan->prev; + + free(orphan->filename); + free_lines(orphan->filetop); +#ifndef NANO_TINY + free(orphan->current_stat); + free(orphan->lock_filename); + /* Free the undo stack. */ + discard_until(NULL, orphan, TRUE); +#endif + + openfile = orphan->prev; + free(orphan); /* When just one buffer remains open, show "Exit" in the help lines. */ if (openfile == openfile->next)