Mercurial > pidgin.yaz
annotate src/gtkmenutray.h @ 11719:109ee3bfeac5
[gaim-migrate @ 14010]
SF Patch #1333770 from corfe83
"Many times in gaim we use the function
g_slist_remove(list,node->data) to remove an element
from a GSList. If we already have the pointer to the
node we want to delete, it is faster to send it the
pointer to the node to delete rather than the data of
the node (we can do this by calling
g_slist_delete_link(list,node)). This change was made
while looking at glib's documentation and the code in
glib's gslist.c.
This is because as the remove/delete function traverses
each node in the list, it doesn't need to spend an
extra memory access to retrieve the data for each
element in the node it is traversing and then compare,
it can simply compare the pointer. In my tests outside
of gaim, this makes a big difference if the node you
are deleting is at a high index in the list. However,
even if you're deleting the first node, it about breaks
even.
So, I've found each case in gaim where we are calling
g_slist_remove, and we already have the pointer to the
appropriate node to delete (this is often the case when
we're doing a for or while loop on a GSList). I've then
replaced it with the appropriate call to
g_slist_delete_link. I, however, didn't do this in
situations where we are explicitly removing the first
element in the list, because in those situations it is
an unnecessary change.
There should be no difference in behavior, but just in
case I've tried running it with valgrind, which reports
the same number of memory leaks after my patch as
before my patch. Of course, I can't guarantee that my
normal behavior on gaim is hitting all the functions
I've changed, but in general testing it Works For Me (tm)."
As with the last patch, this one may not have a practical performance impact (or maybe it does, I have no idea), but it's not worse for any case. Given two ways of doing things where one is always at least as fast and may be faster under some cases, I like to prefer that faster way. This doesn't make the code any uglier, so I'm applying.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sat, 22 Oct 2005 20:48:18 +0000 |
parents | 767e3c0c5062 |
children | 34ea75bdd0c9 |
rev | line source |
---|---|
11553 | 1 /** |
2 * @file gtkmenutray.h GTK+ Tray menu item | |
3 * @ingroup gtkui | |
4 * | |
5 * Gaim is the legal property of its developers, whose names are too numerous | |
6 * to list here. Please refer to the COPYRIGHT file distributed with this | |
7 * source distribution. | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
23 #ifndef GAIM_GTK_MENU_TRAY_H | |
24 #define GAIM_GTK_MENU_TRAY_H | |
25 | |
26 #include <gtk/gtkhbox.h> | |
27 #include <gtk/gtkmenuitem.h> | |
28 | |
29 #define GAIM_GTK_TYPE_MENU_TRAY (gaim_gtk_menu_tray_get_gtype()) | |
30 #define GAIM_GTK_MENU_TRAY(obj) (GTK_CHECK_CAST((obj), GAIM_GTK_TYPE_MENU_TRAY, GaimGtkMenuTray)) | |
31 #define GAIM_GTK_MENU_TRAY_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GAIM_GTK_TYPE_MENU_TRAY, GaimGtkMenuTrayClass)) | |
32 #define GAIM_GTK_IS_MENU_TRAY(obj) (GTK_CHECK_TYPE((obj), GAIM_GTK_TYPE_MENU_TRAY)) | |
33 #define GAIM_GTK_IS_MENU_TRAY_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GAIM_GTK_TYPE_MENU_TRAY)) | |
34 #define GAIM_GTK_MENU_TRAY_GET_CLASS(obj) (GTK_CHECK_GET_CLASS((obj), GAIM_GTK_TYPE_MENU_TRAY, GaimGtkMenuTrayClass)) | |
35 | |
36 typedef struct _GaimGtkMenuTray GaimGtkMenuTray; | |
37 typedef struct _GaimGtkMenuTrayClass GaimGtkMenuTrayClass; | |
38 | |
39 /** A GaimGtkMenuTray */ | |
40 struct _GaimGtkMenuTray { | |
41 GtkMenuItem gparent; /**< The parent instance */ | |
11599
767e3c0c5062
[gaim-migrate @ 13869]
Gary Kramlich <grim@reaperworld.com>
parents:
11558
diff
changeset
|
42 GtkWidget *tray; /**< The tray */ |
11553 | 43 }; |
44 | |
45 /** A GaimGtkMenuTrayClass */ | |
46 struct _GaimGtkMenuTrayClass { | |
47 GtkMenuItemClass gparent; /**< The parent class */ | |
48 }; | |
49 | |
50 G_BEGIN_DECLS | |
51 | |
52 /** | |
53 * Registers the GaimGtkMenuTray class if necessary and returns the | |
54 * type ID assigned to it. | |
55 * | |
56 * @return The GaimGtkMenuTray type ID | |
57 */ | |
58 GType gaim_gtk_menu_tray_get_gtype(void); | |
59 | |
60 /** | |
61 * Creates a new GaimGtkMenuTray | |
62 * | |
63 * @return A new GaimGtkMenuTray | |
64 */ | |
65 GtkWidget *gaim_gtk_menu_tray_new(); | |
66 | |
67 /** | |
68 * Gets the box for the GaimGtkMenuTray | |
69 * | |
70 * @param menu_tray The GaimGtkMenuTray | |
71 * | |
72 * @return The box that this menu tray is using | |
73 */ | |
74 GtkWidget *gaim_gtk_menu_tray_get_box(GaimGtkMenuTray *menu_tray); | |
75 | |
76 /** | |
77 * Appends a widget into the tray | |
78 * | |
79 * @param menu_tray The tray | |
80 * @param widget The widget | |
81 */ | |
82 void gaim_gtk_menu_tray_append(GaimGtkMenuTray *menu_tray, GtkWidget *widget); | |
83 | |
84 /** | |
85 * Prepends a widget into the tray | |
86 * | |
87 * @param menu_tray The try | |
88 * @param widget The widget | |
89 */ | |
90 void gaim_gtk_menu_tray_prepend(GaimGtkMenuTray *menu_tray, GtkWidget *widget); | |
91 | |
92 G_END_DECLS | |
93 | |
94 #endif /* GAIM_GTK_MENU_TRAY_H */ |