From 17f5c056ca73bb0617db807a28d8d0d8d31c2473 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey <pooka109@gmail.com> Date: Thu, 9 Feb 2017 16:00:07 -0600 Subject: [PATCH] tweaks: reduce duplicate code in new_magicline() and move_to_filestruct() These two functions unnecessarily copy make_new_node(); use that instead. --- src/nano.c | 6 +----- src/utils.c | 8 +------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/nano.c b/src/nano.c index e06458bb..9285c98f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -353,14 +353,10 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot, } /* Since the text has now been saved, remove it from the filestruct. */ - openfile->fileage = (filestruct *)nmalloc(sizeof(filestruct)); + openfile->fileage = make_new_node(NULL); openfile->fileage->data = mallocstrcpy(NULL, ""); openfile->filebot = openfile->fileage; -#ifndef DISABLE_COLOR - openfile->fileage->multidata = NULL; -#endif - /* Restore the current line and cursor position. If the mark begins * inside the partition, set the beginning of the mark to where the * saved text used to start. */ diff --git a/src/utils.c b/src/utils.c index 4d018f81..07dad2d7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -530,14 +530,8 @@ size_t strlenpt(const char *text) /* Append a new magicline to filebot. */ void new_magicline(void) { - openfile->filebot->next = (filestruct *)nmalloc(sizeof(filestruct)); + openfile->filebot->next = make_new_node(openfile->filebot); openfile->filebot->next->data = mallocstrcpy(NULL, ""); - openfile->filebot->next->prev = openfile->filebot; - openfile->filebot->next->next = NULL; - openfile->filebot->next->lineno = openfile->filebot->lineno + 1; -#ifndef DISABLE_COLOR - openfile->filebot->next->multidata = NULL; -#endif openfile->filebot = openfile->filebot->next; openfile->totsize++; } -- GitLab