commit 80552aeab7925103cb278f6a8e55aec65928b9e6
parent dfbabc04114657d1e302c3ae5f1d841d08eaf151
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Tue, 14 Jun 2016 12:06:58 +0200
tweaks: elide an intermediate copy of some line data
Diffstat:
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/src/nano.c b/src/nano.c
@@ -246,23 +246,20 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
* at (filebot, strlen(filebot->data)) again. */
void unpartition_filestruct(partition **p)
{
- char *tmp;
-
assert(p != NULL && openfile->fileage != NULL && openfile->filebot != NULL);
/* 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. */
- tmp = mallocstrcpy(NULL, openfile->fileage->data);
openfile->fileage->prev = (*p)->top_prev;
if (openfile->fileage->prev != NULL)
openfile->fileage->prev->next = openfile->fileage;
openfile->fileage->data = charealloc(openfile->fileage->data,
strlen((*p)->top_data) + strlen(openfile->fileage->data) + 1);
- strcpy(openfile->fileage->data, (*p)->top_data);
+ charmove(openfile->fileage->data + strlen((*p)->top_data),
+ openfile->fileage->data, strlen(openfile->fileage->data) + 1);
+ strncpy(openfile->fileage->data, (*p)->top_data, strlen((*p)->top_data));
free((*p)->top_data);
- strcat(openfile->fileage->data, tmp);
- free(tmp);
/* Reattach the line below the bottom of the partition, and restore
* the text after bot_x from bot_data. Free bot_data when we're