Updating branch refs/heads/master to 23c7b01c285078e6346e1b65afcb611273ce3c2f (commit) from a4f297b08aa19d2aa06c969d821af3590a231a2a (commit)
commit 23c7b01c285078e6346e1b65afcb611273ce3c2f Author: Nick Schermer <n...@xfce.org> Date: Thu May 10 16:13:39 2007 +0000 * mousepad/mousepad-undo.c: Don't store a string (or even prepend it in a GString) when the user is inserting text. This saves a whole bunch of relocations (Bug #2737). We also flush the insert buffer after a redo and don't copy strings when inverting a delete step. This should bring the memory usage of the undo manager to a minimum. * TODO: Add some undo manager reminders. * mousepad/mousepad-window.c: Fix compiler warning when debugging is enabled. * mousepad/mousepad-application.c: Change from append to prepend. (Old svn revision: 25700) ChangeLog | 14 +++++++++++ TODO | 9 +++++++ mousepad/mousepad-application.c | 2 +- mousepad/mousepad-undo.c | 50 +++++++++++++++++++++++++++++--------- mousepad/mousepad-window.c | 2 +- 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea45543..f82103a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-05-10 Nick Schermer <n...@xfce.org> + * mousepad/mousepad-undo.c: Don't store a string (or even + prepend it in a GString) when the user is inserting text. + This saves a whole bunch of relocations (Bug #2737). We also + flush the insert buffer after a redo and don't copy strings + when inverting a delete step. This should bring the memory + usage of the undo manager to a minimum. + * TODO: Add some undo manager reminders. + * mousepad/mousepad-window.c: Fix compiler warning when + debugging is enabled. + * mousepad/mousepad-application.c: Change from append to + prepend. + + 2007-05-08 Nick Schermer <n...@xfce.org> * mousepad/mousepad-window.c: Rename function so it matches the standard mousepad_window_* names. diff --git a/TODO b/TODO index fe0db97..8f30a10 100644 --- a/TODO +++ b/TODO @@ -35,6 +35,15 @@ Text View - Maybe a match whole word option. +Undo Manager +============ +- Replace g_list_append with g_list_prepend in the undo manager. See + glib manual why. +- We erase the GString in the undo manager, but this buffer will be + (very) large when a large bunch of text is deleted. Maybe not a big + problem, but we could shrink it after erasing. + + Saving and loading ================== - Save All option. diff --git a/mousepad/mousepad-application.c b/mousepad/mousepad-application.c index 7054862..dcb0bc9 100644 --- a/mousepad/mousepad-application.c +++ b/mousepad/mousepad-application.c @@ -204,7 +204,7 @@ mousepad_application_take_window (MousepadApplication *application, g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (mousepad_application_window_destroyed), application); /* add the window to our internal list */ - application->windows = g_slist_append (application->windows, window); + application->windows = g_slist_prepend (application->windows, window); } diff --git a/mousepad/mousepad-undo.c b/mousepad/mousepad-undo.c index 3fa6fba..1477bf2 100644 --- a/mousepad/mousepad-undo.c +++ b/mousepad/mousepad-undo.c @@ -272,6 +272,10 @@ mousepad_undo_preform_step (MousepadUndo *undo, /* get the end iter */ gtk_text_buffer_get_iter_at_offset (undo->buffer, &end_iter, info->end); + /* set the string */ + if (info->string == NULL) + info->string = gtk_text_buffer_get_slice (undo->buffer, &start_iter, &end_iter, TRUE); + /* delete the inserted text */ gtk_text_buffer_delete (undo->buffer, &start_iter, &end_iter); @@ -281,6 +285,14 @@ mousepad_undo_preform_step (MousepadUndo *undo, /* insert the deleted text */ gtk_text_buffer_insert (undo->buffer, &start_iter, info->string, -1); + /* cleanup the buffer if the user did a redo step (so an inverted insert step) */ + if (!undo_step) + { + /* free and reset */ + g_free (info->string); + info->string = NULL; + } + break; default: @@ -295,7 +307,7 @@ mousepad_undo_preform_step (MousepadUndo *undo, undo->steps_position++; } - /* set the can_undo boolean */ + /* whether we can undo and redo */ undo->can_undo = (undo->steps_position > 0); undo->can_redo = (undo->steps_position < g_list_length (undo->steps)); @@ -338,10 +350,17 @@ mousepad_undo_new_step (MousepadUndo *undo) /* allocate a new slice */ info = g_slice_new0 (MousepadUndoInfo); - /* copy the data from the existing step */ - info->string = g_strdup (existing->string); - info->start = existing->start; - info->end = existing->end; + /* copy the data from the existing step, ignore delete + * action string since they will be inverted to insert + * actions*/ + if (existing->action == INSERT) + info->string = g_strdup (existing->string); + else + info->string = NULL; + + /* set the start and end position */ + info->start = existing->start; + info->end = existing->end; /* set the inverted action */ info->action = (existing->action == INSERT ? DELETE : INSERT); @@ -353,12 +372,18 @@ mousepad_undo_new_step (MousepadUndo *undo) /* allocate the slice */ info = g_slice_new0 (MousepadUndoInfo); - /* set the info */ - info->string = g_strdup (undo->step_buffer->str); + /* set the action, start- and end-position */ info->action = undo->step_action; info->start = undo->step_start; info->end = undo->step_end; + /* only set the string if we delete text. if we insert text the + * string will be set before we delete it when undoing */ + if (undo->step_action == INSERT) + info->string = NULL; + else + info->string = g_strdup (undo->step_buffer->str); + /* append to the steps list */ undo->steps = g_list_append (undo->steps, info); @@ -428,10 +453,8 @@ mousepad_undo_handle_step (const gchar *text, /* check if we can append (insert action) */ if (undo->step_action == action && action == INSERT && undo->step_end == start) { - /* append the inserted string */ - undo->step_buffer = g_string_append_len (undo->step_buffer, text, length); - - /* update the end position */ + /* update the end position. we don't have to prepend the inserted text since + * we don't store this when creating a new step */ undo->step_end = end; } /* check if we can prepend (delete action) */ @@ -456,8 +479,11 @@ new_step: /* only start a new step when the char was not a space */ if (create_new_step) { + /* start building a new string if we delete text */ + if (action == DELETE) + undo->step_buffer = g_string_append_len (undo->step_buffer, text, length); + /* set the new info */ - undo->step_buffer = g_string_append_len (undo->step_buffer, text, ABS (start - end)); undo->step_action = action; undo->step_start = start; undo->step_end = end; diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c index 4f50997..d981df2 100644 --- a/mousepad/mousepad-window.c +++ b/mousepad/mousepad-window.c @@ -1359,7 +1359,7 @@ mousepad_window_notebook_button_press_event (GtkNotebook *notebook, guint page_num = 0; gint x_root; - _mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window)); + _mousepad_return_val_if_fail (MOUSEPAD_IS_WINDOW (window), FALSE); if (event->type == GDK_BUTTON_PRESS && event->button == 3) { _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits