gtk+ r20161 - in trunk: . gtk



Author: matthiasc
Date: Sun May 25 22:33:34 2008
New Revision: 20161
URL: http://svn.gnome.org/viewvc/gtk+?rev=20161&view=rev

Log:
        Bug 501730 â use GSlice for small allocs

        * gtk/gtkmenuitem.c:
        * gtk/gtkmenu.c: Use the slice allocator for small allocations.
        Patch by Christian Persch.



Modified:
   trunk/ChangeLog
   trunk/gtk/gtkmenu.c
   trunk/gtk/gtkmenuitem.c

Modified: trunk/gtk/gtkmenu.c
==============================================================================
--- trunk/gtk/gtkmenu.c	(original)
+++ trunk/gtk/gtkmenu.c	Sun May 25 22:33:34 2008
@@ -265,6 +265,12 @@
   gtk_widget_queue_resize (GTK_WIDGET (menu));
 }
 
+static void
+attach_info_free (AttachInfo *info)
+{
+  g_slice_free (AttachInfo, info);
+}
+
 static AttachInfo *
 get_attach_info (GtkWidget *child)
 {
@@ -273,8 +279,8 @@
 
   if (!ai)
     {
-      ai = g_new0 (AttachInfo, 1);
-      g_object_set_data_full (object, I_(ATTACH_INFO_KEY), ai, g_free);
+      ai = g_slice_new0 (AttachInfo);
+      g_object_set_data_full (object, I_(ATTACH_INFO_KEY), ai, attach_info_free);
     }
 
   return ai;
@@ -1024,7 +1030,7 @@
   
   g_object_ref_sink (menu);
   
-  data = g_new (GtkMenuAttachData, 1);
+  data = g_slice_new (GtkMenuAttachData);
   data->attach_widget = attach_widget;
   
   g_signal_connect (attach_widget, "screen_changed",
@@ -1098,7 +1104,7 @@
   if (GTK_WIDGET_REALIZED (menu))
     gtk_widget_unrealize (GTK_WIDGET (menu));
   
-  g_free (data);
+  g_slice_free (GtkMenuAttachData, data);
   
   /* Fallback title for menu comes from attach widget */
   gtk_menu_update_title (menu);
@@ -1644,12 +1650,15 @@
 gtk_menu_set_accel_path (GtkMenu     *menu,
 			 const gchar *accel_path)
 {
+  gchar *old_accel_path;
+
   g_return_if_fail (GTK_IS_MENU (menu));
   if (accel_path)
     g_return_if_fail (accel_path[0] == '<' && strchr (accel_path, '/')); /* simplistic check */
 
-  g_free (menu->accel_path);
+  old_accel_path = menu->accel_path;
   menu->accel_path = g_strdup (accel_path);
+  g_free (old_accel_path);
   if (menu->accel_path)
     _gtk_menu_refresh_accel_paths (menu, FALSE);
 }

Modified: trunk/gtk/gtkmenuitem.c
==============================================================================
--- trunk/gtk/gtkmenuitem.c	(original)
+++ trunk/gtk/gtkmenuitem.c	Sun May 25 22:33:34 2008
@@ -1077,6 +1077,12 @@
 }
 
 static void
+free_timeval (GTimeVal *val)
+{
+  g_slice_free (GTimeVal, val);
+}
+
+static void
 gtk_menu_item_real_popup_submenu (GtkWidget *widget,
                                   gboolean   remember_exact_time)
 {
@@ -1092,13 +1098,13 @@
 
       if (remember_exact_time)
         {
-          GTimeVal *popup_time = g_new0 (GTimeVal, 1);
+          GTimeVal *popup_time = g_slice_new0 (GTimeVal);
 
           g_get_current_time (popup_time);
 
           g_object_set_data_full (G_OBJECT (menu_item->submenu),
                                   "gtk-menu-exact-popup-time", popup_time,
-                                  (GDestroyNotify) g_free);
+                                  (GDestroyNotify) free_timeval);
         }
       else
         {
@@ -1603,6 +1609,7 @@
 			      const gchar *accel_path)
 {
   GtkWidget *widget;
+  gchar *old_accel_path;
 
   g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
   g_return_if_fail (accel_path == NULL ||
@@ -1611,8 +1618,9 @@
   widget = GTK_WIDGET (menu_item);
 
   /* store new path */
-  g_free (menu_item->accel_path);
+  old_accel_path = menu_item->accel_path;
   menu_item->accel_path = g_strdup (accel_path);
+  g_free (old_accel_path);
 
   /* forget accelerators associated with old path */
   gtk_widget_set_accel_path (widget, NULL, NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]