tweaks: don't bother saving and restoring 'cutbottom' all the time

The 'cutbottom' variable is only ever used when cutting or copying
consecutive lines: for appending the current line to the already
existing lines in the cutbuffer.  As soon as some other operation
is performed, 'cutbottom' becomes irrelevant, it could be set to
anything, it doesn't matter: the pasting of the cutbuffer does not
use the value of 'cutbottom', nor does any other operation.
master
Benno Schulenberg 2019-04-28 19:21:40 +02:00
parent 9e44a53be7
commit 2b9dd6c574
3 changed files with 15 additions and 38 deletions

View File

@ -148,12 +148,10 @@ void chop_word(bool forward)
/* Remember the current cursor position. */ /* Remember the current cursor position. */
linestruct *is_current = openfile->current; linestruct *is_current = openfile->current;
size_t is_current_x = openfile->current_x; size_t is_current_x = openfile->current_x;
/* Remember where the cutbuffer is, then make it seem blank. */
/* Remember where the cutbuffer is and then make it seem blank. */
linestruct *is_cutbuffer = cutbuffer; linestruct *is_cutbuffer = cutbuffer;
linestruct *is_cutbottom = cutbottom;
cutbuffer = NULL; cutbuffer = NULL;
cutbottom = NULL;
/* Move the cursor to a word start, to the left or to the right. /* Move the cursor to a word start, to the left or to the right.
* If that word is on another line and the cursor was not already * If that word is on another line and the cursor was not already
@ -191,7 +189,6 @@ void chop_word(bool forward)
/* Discard the cut word and restore the cutbuffer. */ /* Discard the cut word and restore the cutbuffer. */
free_lines(cutbuffer); free_lines(cutbuffer);
cutbuffer = is_cutbuffer; cutbuffer = is_cutbuffer;
cutbottom = is_cutbottom;
} }
/* Delete a word leftward. */ /* Delete a word leftward. */
@ -450,7 +447,6 @@ void zap_text(void)
{ {
/* Remember the current cutbuffer so it can be restored after the zap. */ /* Remember the current cutbuffer so it can be restored after the zap. */
linestruct *was_cutbuffer = cutbuffer; linestruct *was_cutbuffer = cutbuffer;
linestruct *was_cutbottom = cutbottom;
if (!is_cuttable(ISSET(CUT_FROM_CURSOR) && openfile->mark == NULL)) if (!is_cuttable(ISSET(CUT_FROM_CURSOR) && openfile->mark == NULL))
return; return;
@ -464,14 +460,12 @@ void zap_text(void)
/* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */ /* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */
cutbuffer = openfile->current_undo->cutbuffer; cutbuffer = openfile->current_undo->cutbuffer;
cutbottom = openfile->current_undo->cutbottom;
do_cut_text(FALSE, openfile->mark != NULL, FALSE, TRUE); do_cut_text(FALSE, openfile->mark != NULL, FALSE, TRUE);
update_undo(ZAP); update_undo(ZAP);
cutbuffer = was_cutbuffer; cutbuffer = was_cutbuffer;
cutbottom = was_cutbottom;
} }
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */

View File

@ -330,12 +330,8 @@ typedef struct undo {
/* Some flag data we need. */ /* Some flag data we need. */
undo_group *grouping; undo_group *grouping;
/* Undo info specific to groups of lines. */ /* Undo info specific to groups of lines. */
/* Cut-specific stuff we need. */
linestruct *cutbuffer; linestruct *cutbuffer;
/* Copy of the cutbuffer. */ /* Copy of the cutbuffer. */
linestruct *cutbottom;
/* Copy of cutbottom. */
ssize_t mark_begin_lineno; ssize_t mark_begin_lineno;
/* Mostly the line number of the current line; sometimes something else. */ /* Mostly the line number of the current line; sometimes something else. */
size_t mark_begin_x; size_t mark_begin_x;

View File

@ -490,7 +490,7 @@ void undo_cut(undo *u)
/* Redo a cut, or undo an uncut. */ /* Redo a cut, or undo an uncut. */
void redo_cut(undo *u) void redo_cut(undo *u)
{ {
linestruct *oldcutbuffer = cutbuffer, *oldcutbottom = cutbottom; linestruct *oldcutbuffer = cutbuffer;
goto_line_posx(u->lineno, u->begin); goto_line_posx(u->lineno, u->begin);
@ -499,7 +499,6 @@ void redo_cut(undo *u)
return; return;
cutbuffer = NULL; cutbuffer = NULL;
cutbottom = NULL;
openfile->mark = fsfromline(u->mark_begin_lineno); openfile->mark = fsfromline(u->mark_begin_lineno);
openfile->mark_x = (u->xflags & WAS_WHOLE_LINE) ? 0 : u->mark_begin_x; openfile->mark_x = (u->xflags & WAS_WHOLE_LINE) ? 0 : u->mark_begin_x;
@ -508,7 +507,6 @@ void redo_cut(undo *u)
free_lines(cutbuffer); free_lines(cutbuffer);
cutbuffer = oldcutbuffer; cutbuffer = oldcutbuffer;
cutbottom = oldcutbottom;
} }
/* Undo the last thing(s) we did. */ /* Undo the last thing(s) we did. */
@ -516,7 +514,7 @@ void do_undo(void)
{ {
undo *u = openfile->current_undo; undo *u = openfile->current_undo;
linestruct *f = NULL, *t = NULL; linestruct *f = NULL, *t = NULL;
linestruct *oldcutbuffer, *oldcutbottom; linestruct *oldcutbuffer;
char *data, *undidmsg = NULL; char *data, *undidmsg = NULL;
size_t from_x, to_x; size_t from_x, to_x;
@ -622,18 +620,14 @@ void do_undo(void)
case INSERT: case INSERT:
undidmsg = _("insertion"); undidmsg = _("insertion");
oldcutbuffer = cutbuffer; oldcutbuffer = cutbuffer;
oldcutbottom = cutbottom;
cutbuffer = NULL; cutbuffer = NULL;
cutbottom = NULL;
openfile->mark = fsfromline(u->mark_begin_lineno); openfile->mark = fsfromline(u->mark_begin_lineno);
openfile->mark_x = u->mark_begin_x; openfile->mark_x = u->mark_begin_x;
goto_line_posx(u->lineno, u->begin); goto_line_posx(u->lineno, u->begin);
cut_marked(NULL); cut_marked(NULL);
free_lines(u->cutbuffer); free_lines(u->cutbuffer);
u->cutbuffer = cutbuffer; u->cutbuffer = cutbuffer;
u->cutbottom = cutbottom;
cutbuffer = oldcutbuffer; cutbuffer = oldcutbuffer;
cutbottom = oldcutbottom;
break; break;
case COUPLE_BEGIN: case COUPLE_BEGIN:
undidmsg = u->strdata; undidmsg = u->strdata;
@ -1141,7 +1135,6 @@ void add_undo(undo_type action)
u->type = action; u->type = action;
u->strdata = NULL; u->strdata = NULL;
u->cutbuffer = NULL; u->cutbuffer = NULL;
u->cutbottom = NULL;
u->lineno = openfile->current->lineno; u->lineno = openfile->current->lineno;
u->begin = openfile->current_x; u->begin = openfile->current_x;
u->mark_begin_lineno = openfile->current->lineno; u->mark_begin_lineno = openfile->current->lineno;
@ -1377,19 +1370,21 @@ void update_undo(undo_type action)
} else } else
u->xflags |= WAS_MARKED_FORWARD; u->xflags |= WAS_MARKED_FORWARD;
} else { } else {
/* Compute the end of the cut for the undo, using our copy. */ linestruct *bottomline = u->cutbuffer;
u->cutbottom = u->cutbuffer;
while (u->cutbottom->next != NULL) /* Find the end of the cut for the undo/redo, using our copy. */
u->cutbottom = u->cutbottom->next; while (bottomline->next != NULL)
u->lineno = u->mark_begin_lineno + u->cutbottom->lineno - bottomline = bottomline->next;
u->lineno = u->mark_begin_lineno + bottomline->lineno -
u->cutbuffer->lineno; u->cutbuffer->lineno;
if (ISSET(CUT_FROM_CURSOR) || u->type == CUT_TO_EOF) { if (ISSET(CUT_FROM_CURSOR) || u->type == CUT_TO_EOF) {
u->begin = strlen(u->cutbottom->data); u->begin = strlen(bottomline->data);
if (u->lineno == u->mark_begin_lineno) if (u->lineno == u->mark_begin_lineno)
u->begin += u->mark_begin_x; u->begin += u->mark_begin_x;
} else if (openfile->current == openfile->filebot && } else if (openfile->current == openfile->filebot &&
ISSET(NO_NEWLINES)) ISSET(NO_NEWLINES))
u->begin = strlen(u->cutbottom->data); u->begin = strlen(bottomline->data);
} }
break; break;
case INSERT: case INSERT:
@ -1926,8 +1921,6 @@ void do_justify(bool full_justify)
/* The bottom x-coordinate of the paragraph we justify. */ /* The bottom x-coordinate of the paragraph we justify. */
linestruct *was_cutbuffer = cutbuffer; linestruct *was_cutbuffer = cutbuffer;
/* The old cutbuffer, so we can justify in the current cutbuffer. */ /* The old cutbuffer, so we can justify in the current cutbuffer. */
linestruct *was_cutbottom = cutbottom;
/* The old cutbottom, so we can justify in the current cutbuffer. */
linestruct *jusline; linestruct *jusline;
/* The line that we're justifying in the current cutbuffer. */ /* The line that we're justifying in the current cutbuffer. */
@ -2053,7 +2046,6 @@ void do_justify(bool full_justify)
/* Do the equivalent of a marked cut into an empty cutbuffer. */ /* Do the equivalent of a marked cut into an empty cutbuffer. */
cutbuffer = NULL; cutbuffer = NULL;
cutbottom = NULL;
extract_buffer(&cutbuffer, &cutbottom, first_par_line, top_x, extract_buffer(&cutbuffer, &cutbottom, first_par_line, top_x,
last_par_line, bot_x); last_par_line, bot_x);
#ifndef NANO_TINY #ifndef NANO_TINY
@ -2106,8 +2098,6 @@ void do_justify(bool full_justify)
} else } else
rewrap_paragraph(&line, the_lead, lead_len); rewrap_paragraph(&line, the_lead, lead_len);
cutbottom = line;
/* If the marked region started after the beginning of a line, insert /* If the marked region started after the beginning of a line, insert
* a new line before the new paragraph. But if the region started in * a new line before the new paragraph. But if the region started in
* the middle of the line's leading part, no new line is needed: just * the middle of the line's leading part, no new line is needed: just
@ -2130,10 +2120,8 @@ void do_justify(bool full_justify)
* portion, so it will become a full leading part when the justified * portion, so it will become a full leading part when the justified
* region is "pasted" back. */ * region is "pasted" back. */
if (bot_x > 0 && !ends_at_eol) { if (bot_x > 0 && !ends_at_eol) {
cutbottom->next = make_new_node(cutbottom); line->next = make_new_node(line);
cutbottom->next->data = mallocstrcpy(NULL, the_lead + line->next->data = mallocstrcpy(NULL, the_lead + needed_bot_extra);
needed_bot_extra);
cutbottom = cutbottom->next;
} }
free(the_lead); free(the_lead);
@ -2183,7 +2171,6 @@ void do_justify(bool full_justify)
/* We're done justifying. Restore the old cutbuffer. */ /* We're done justifying. Restore the old cutbuffer. */
cutbuffer = was_cutbuffer; cutbuffer = was_cutbuffer;
cutbottom = was_cutbottom;
/* Show what we justified on the status bar. */ /* Show what we justified on the status bar. */
#ifndef NANO_TINY #ifndef NANO_TINY