[Xfce4-commits] r25700 - in mousepad/branches/nick_0_3: . mousepad

Nick Schermer nick at xfce.org
Thu May 10 18:13:39 CEST 2007


Author: nick
Date: 2007-05-10 16:13:39 +0000 (Thu, 10 May 2007)
New Revision: 25700

Modified:
   mousepad/branches/nick_0_3/ChangeLog
   mousepad/branches/nick_0_3/TODO
   mousepad/branches/nick_0_3/mousepad/mousepad-application.c
   mousepad/branches/nick_0_3/mousepad/mousepad-undo.c
   mousepad/branches/nick_0_3/mousepad/mousepad-window.c
Log:
	* 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.

Modified: mousepad/branches/nick_0_3/ChangeLog
===================================================================
--- mousepad/branches/nick_0_3/ChangeLog	2007-05-10 10:02:38 UTC (rev 25699)
+++ mousepad/branches/nick_0_3/ChangeLog	2007-05-10 16:13:39 UTC (rev 25700)
@@ -1,3 +1,17 @@
+2007-05-10	Nick Schermer <nick at 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 <nick at xfce.org>
 	* mousepad/mousepad-window.c: Rename function so it matches
 	  the standard mousepad_window_* names.

Modified: mousepad/branches/nick_0_3/TODO
===================================================================
--- mousepad/branches/nick_0_3/TODO	2007-05-10 10:02:38 UTC (rev 25699)
+++ mousepad/branches/nick_0_3/TODO	2007-05-10 16:13:39 UTC (rev 25700)
@@ -35,6 +35,15 @@
 - 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.

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-application.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-application.c	2007-05-10 10:02:38 UTC (rev 25699)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-application.c	2007-05-10 16:13:39 UTC (rev 25700)
@@ -204,7 +204,7 @@
   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);
 }
 
 

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-undo.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-undo.c	2007-05-10 10:02:38 UTC (rev 25699)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-undo.c	2007-05-10 16:13:39 UTC (rev 25700)
@@ -272,6 +272,10 @@
             /* 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 @@
             /* 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 @@
         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,11 +350,18 @@
         /* 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 @@
   /* 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 @@
   /* 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 @@
   /* 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;

Modified: mousepad/branches/nick_0_3/mousepad/mousepad-window.c
===================================================================
--- mousepad/branches/nick_0_3/mousepad/mousepad-window.c	2007-05-10 10:02:38 UTC (rev 25699)
+++ mousepad/branches/nick_0_3/mousepad/mousepad-window.c	2007-05-10 16:13:39 UTC (rev 25700)
@@ -1359,7 +1359,7 @@
   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)
     {



More information about the Xfce4-commits mailing list