Commit f9103a5c authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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.
No related merge requests found
Showing with 15 additions and 12 deletions
+15 -12
...@@ -163,8 +163,9 @@ typedef enum { ...@@ -163,8 +163,9 @@ typedef enum {
CENTERING, FLOWING, STATIONARY CENTERING, FLOWING, STATIONARY
} update_type; } update_type;
/* The kinds of undo actions. ADD...REPLACE must come first. */
typedef enum { typedef enum {
ADD, DEL, BACK, CUT, CUT_TO_EOF, REPLACE, ADD, BACK, DEL, ENTER, JOIN, REPLACE,
#ifdef ENABLE_WRAPPING #ifdef ENABLE_WRAPPING
SPLIT_BEGIN, SPLIT_END, SPLIT_BEGIN, SPLIT_END,
#endif #endif
...@@ -172,7 +173,7 @@ typedef enum { ...@@ -172,7 +173,7 @@ typedef enum {
#ifdef ENABLE_COMMENT #ifdef ENABLE_COMMENT
COMMENT, UNCOMMENT, PREFLIGHT, COMMENT, UNCOMMENT, PREFLIGHT,
#endif #endif
JOIN, PASTE, INSERT, ENTER, OTHER CUT, CUT_TO_EOF, PASTE, INSERT, OTHER
} undo_type; } undo_type;
/* Structure types. */ /* Structure types. */
......
...@@ -678,7 +678,7 @@ void redo_cut(undo *u) ...@@ -678,7 +678,7 @@ void redo_cut(undo *u)
void do_undo(void) void do_undo(void)
{ {
undo *u = openfile->current_undo; undo *u = openfile->current_undo;
filestruct *f, *t = NULL; filestruct *f = NULL, *t = NULL;
filestruct *oldcutbuffer, *oldcutbottom; filestruct *oldcutbuffer, *oldcutbottom;
char *data, *undidmsg = NULL; char *data, *undidmsg = NULL;
size_t from_x, to_x; size_t from_x, to_x;
...@@ -688,13 +688,14 @@ void do_undo(void) ...@@ -688,13 +688,14 @@ void do_undo(void)
return; return;
} }
f = fsfromline(u->mark_begin_lineno); if (u->type <= REPLACE) {
if (!f) f = fsfromline(u->mark_begin_lineno);
return; if (f == NULL)
return;
}
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " >> Undoing a type %d...\n", u->type); fprintf(stderr, " >> Undoing a type %d...\n", u->type);
fprintf(stderr, " >> Data we're about to undo = \"%s\"\n", f->data);
#endif #endif
openfile->current_x = u->begin; openfile->current_x = u->begin;
...@@ -848,7 +849,7 @@ void do_undo(void) ...@@ -848,7 +849,7 @@ void do_undo(void)
/* Redo the last thing(s) we undid. */ /* Redo the last thing(s) we undid. */
void do_redo(void) void do_redo(void)
{ {
filestruct *f, *shoveline; filestruct *f = NULL, *shoveline;
char *data, *redidmsg = NULL; char *data, *redidmsg = NULL;
undo *u = openfile->undotop; undo *u = openfile->undotop;
...@@ -866,13 +867,14 @@ void do_redo(void) ...@@ -866,13 +867,14 @@ void do_redo(void)
return; return;
} }
f = fsfromline(u->type == INSERT ? 1 : u->mark_begin_lineno); if (u->type <= REPLACE) {
if (!f) f = fsfromline(u->mark_begin_lineno);
return; if (f == NULL)
return;
}
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, " >> Redo running for type %d\n", u->type); fprintf(stderr, " >> Redo running for type %d\n", u->type);
fprintf(stderr, " >> Data we're about to redo = \"%s\"\n", f->data);
#endif #endif
switch (u->type) { switch (u->type) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment