tweaks: make the fsfromline() call only for the undo types that need it

The 'f' variable is used only in the ADD, BACK, DEL, ENTER, JOIN, and
REPLACE undo/redo cases.  So, avoid making a somewhat costly call when
it is entirely superfluous.  Rearrange the undo types to make checking
for the above six types easier.
master
Benno Schulenberg 2018-03-03 16:54:55 +01:00
parent e9eabdcdcb
commit f9103a5cb5
2 changed files with 15 additions and 12 deletions

View File

@ -163,8 +163,9 @@ typedef enum {
CENTERING, FLOWING, STATIONARY
} update_type;
/* The kinds of undo actions. ADD...REPLACE must come first. */
typedef enum {
ADD, DEL, BACK, CUT, CUT_TO_EOF, REPLACE,
ADD, BACK, DEL, ENTER, JOIN, REPLACE,
#ifdef ENABLE_WRAPPING
SPLIT_BEGIN, SPLIT_END,
#endif
@ -172,7 +173,7 @@ typedef enum {
#ifdef ENABLE_COMMENT
COMMENT, UNCOMMENT, PREFLIGHT,
#endif
JOIN, PASTE, INSERT, ENTER, OTHER
CUT, CUT_TO_EOF, PASTE, INSERT, OTHER
} undo_type;
/* Structure types. */

View File

@ -678,7 +678,7 @@ void redo_cut(undo *u)
void do_undo(void)
{
undo *u = openfile->current_undo;
filestruct *f, *t = NULL;
filestruct *f = NULL, *t = NULL;
filestruct *oldcutbuffer, *oldcutbottom;
char *data, *undidmsg = NULL;
size_t from_x, to_x;
@ -688,13 +688,14 @@ void do_undo(void)
return;
}
f = fsfromline(u->mark_begin_lineno);
if (!f)
return;
if (u->type <= REPLACE) {
f = fsfromline(u->mark_begin_lineno);
if (f == NULL)
return;
}
#ifdef DEBUG
fprintf(stderr, " >> Undoing a type %d...\n", u->type);
fprintf(stderr, " >> Data we're about to undo = \"%s\"\n", f->data);
#endif
openfile->current_x = u->begin;
@ -848,7 +849,7 @@ void do_undo(void)
/* Redo the last thing(s) we undid. */
void do_redo(void)
{
filestruct *f, *shoveline;
filestruct *f = NULL, *shoveline;
char *data, *redidmsg = NULL;
undo *u = openfile->undotop;
@ -866,13 +867,14 @@ void do_redo(void)
return;
}
f = fsfromline(u->type == INSERT ? 1 : u->mark_begin_lineno);
if (!f)
return;
if (u->type <= REPLACE) {
f = fsfromline(u->mark_begin_lineno);
if (f == NULL)
return;
}
#ifdef DEBUG
fprintf(stderr, " >> Redo running for type %d\n", u->type);
fprintf(stderr, " >> Data we're about to redo = \"%s\"\n", f->data);
#endif
switch (u->type) {