From 7e9dd385f5081d0ba6978b600ac835e111f08227 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 31 May 2019 19:00:20 +0200 Subject: [PATCH] tweaks: elide a parameter and a return value As 'filepart' is a global variable, there is no need to pass it around. Just use it directly. --- src/files.c | 4 ++-- src/nano.c | 27 ++++++++++++++------------- src/proto.h | 4 ++-- src/text.c | 4 ++-- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/files.c b/src/files.c index 55bb955f..c16ebcb1 100644 --- a/src/files.c +++ b/src/files.c @@ -2000,7 +2000,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp, /* Partition the buffer so that it contains only the marked text. */ get_region((const linestruct **)&top, &top_x, (const linestruct **)&bot, &bot_x, NULL); - filepart = partition_buffer(top, top_x, bot, bot_x); + partition_buffer(top, top_x, bot, bot_x); /* If we are using a magic line, and the last line of the partition * isn't blank, then add a newline at the end of the buffer. */ @@ -2015,7 +2015,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp, remove_magicline(); /* Unpartition the buffer so that it contains all the text again. */ - unpartition_buffer(&filepart); + unpartition_buffer(); return retval; } diff --git a/src/nano.c b/src/nano.c index 55f02033..1bde71e7 100644 --- a/src/nano.c +++ b/src/nano.c @@ -192,8 +192,8 @@ void renumber_from(linestruct *line) /* Partition the current buffer so that it appears to begin at (top, top_x) * and appears to end at (bot, bot_x). */ -partition *partition_buffer(linestruct *top, size_t top_x, - linestruct *bot, size_t bot_x) +void partition_buffer(linestruct *top, size_t top_x, + linestruct *bot, size_t bot_x) { partition *p = nmalloc(sizeof(partition)); @@ -230,14 +230,15 @@ partition *partition_buffer(linestruct *top, size_t top_x, /* Remove all text before top_x at the top of the partition. */ charmove(top->data, top->data + top_x, strlen(top->data) - top_x + 1); - /* Return the partition. */ - return p; + filepart = p; } /* Unpartition the current buffer so that it stretches from (filetop, 0) * to (filebot, $) again. */ -void unpartition_buffer(partition **p) +void unpartition_buffer() { + partition **p = &filepart; + /* Reattach the line above the top of the partition, and restore the * text before top_x from top_data. Free top_data when we're done * with it. */ @@ -270,8 +271,8 @@ void unpartition_buffer(partition **p) openfile->filebot = (*p)->filebot; /* Uninitialize the partition. */ - free(*p); - *p = NULL; + free(filepart); + filepart = NULL; } /* Move all text between (top, top_x) and (bot, bot_x) from the current buffer @@ -293,7 +294,7 @@ void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x) * (top, top_x) to (bot, bot_x), keep track of whether the top of * the edit window is inside the partition, and keep track of * whether the mark begins inside the partition. */ - filepart = partition_buffer(top, top_x, bot, bot_x); + partition_buffer(top, top_x, bot, bot_x); edittop_inside = (openfile->edittop->lineno >= openfile->filetop->lineno && openfile->edittop->lineno <= openfile->filebot->lineno); #ifndef NANO_TINY @@ -358,7 +359,7 @@ void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x) /* Unpartition the buffer so that it contains all the text * again, minus the saved text. */ - unpartition_buffer(&filepart); + unpartition_buffer(); renumber_from(openfile->current); @@ -394,8 +395,8 @@ void ingraft_buffer(linestruct *topline) /* Partition the buffer so that it contains no text, and remember * whether the current line is at the top of the edit window. */ - filepart = partition_buffer(openfile->current, openfile->current_x, - openfile->current, openfile->current_x); + partition_buffer(openfile->current, openfile->current_x, + openfile->current, openfile->current_x); edittop_inside = (openfile->edittop == openfile->filetop); delete_node(openfile->filetop); @@ -437,7 +438,7 @@ void ingraft_buffer(linestruct *topline) /* Unpartition the buffer so that it contains all the text * again, plus the copied text. */ - unpartition_buffer(&filepart); + unpartition_buffer(); renumber_from(topline); @@ -576,7 +577,7 @@ void die(const char *msg, ...) * because it would write files not mentioned on the command line. */ if (openfile->modified && !ISSET(RESTRICTED)) { if (filepart != NULL) - unpartition_buffer(&filepart); + unpartition_buffer(); emergency_save(openfile->filename, openfile->current_stat); } diff --git a/src/proto.h b/src/proto.h index 4e24a367..99a76d91 100644 --- a/src/proto.h +++ b/src/proto.h @@ -393,9 +393,9 @@ void delete_node(linestruct *fileptr); linestruct *copy_buffer(const linestruct *src); void free_lines(linestruct *src); void renumber_from(linestruct *line); -partition *partition_buffer(linestruct *top, size_t top_x, +void partition_buffer(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x); -void unpartition_buffer(partition **p); +void unpartition_buffer(); void extract(linestruct *top, size_t top_x, linestruct *bot, size_t bot_x); void ingraft_buffer(linestruct *somebuffer); void copy_from_buffer(linestruct *somebuffer); diff --git a/src/text.c b/src/text.c index 328f1a3a..174f1a50 100644 --- a/src/text.c +++ b/src/text.c @@ -3039,7 +3039,7 @@ void do_wordlinechar_count(void) if (openfile->mark) { get_region((const linestruct **)&top, &top_x, (const linestruct **)&bot, &bot_x, NULL); - filepart = partition_buffer(top, top_x, bot, bot_x); + partition_buffer(top, top_x, bot, bot_x); } /* Start at the top of the file. */ @@ -3063,7 +3063,7 @@ void do_wordlinechar_count(void) /* Get the number of multibyte characters, similar to "wc -c". */ if (openfile->mark) { chars = get_totsize(openfile->filetop, openfile->filebot); - unpartition_buffer(&filepart); + unpartition_buffer(); } else chars = openfile->totsize;