nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 4f67f364bc08adddedc0afcfc7214008e2cf654c
parent 7cf08b93ffb167332d7a57ab3d0a81fcc23c3160
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 27 Feb 2020 14:14:18 +0100

tweaks: when undoing an addition or redoing a deletion, do not reallocate

Especially when undoing an addition, reallocating the line data is a
waste of time, because most likely other text will be added instead.

(This also removes a coding error in the redo code for a deletion:
it allocated too many bytes for the new line data: twice the amount
of the deletion too much.)

Diffstat:
Msrc/text.c | 14++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -534,11 +534,8 @@ void do_undo(void) undidmsg = _("addition"); if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES)) remove_magicline(); - data = charalloc(strlen(line->data) - strlen(u->strdata) + 1); - strncpy(data, line->data, u->head_x); - strcpy(&data[u->head_x], &line->data[u->head_x + strlen(u->strdata)]); - free(line->data); - line->data = data; + memmove(line->data + u->head_x, line->data + u->head_x + strlen(u->strdata), + strlen(line->data + u->head_x) - strlen(u->strdata) + 1); goto_line_posx(u->head_lineno, u->head_x); break; case ENTER: @@ -723,11 +720,8 @@ void do_redo(void) case BACK: case DEL: redidmsg = _("deletion"); - data = charalloc(strlen(line->data) + strlen(u->strdata) + 1); - strncpy(data, line->data, u->head_x); - strcpy(&data[u->head_x], &line->data[u->head_x + strlen(u->strdata)]); - free(line->data); - line->data = data; + memmove(line->data + u->head_x, line->data + u->head_x + strlen(u->strdata), + strlen(line->data + u->head_x) - strlen(u->strdata) + 1); goto_line_posx(u->head_lineno, u->head_x); break; case JOIN: