Mercurial > pidgin
annotate src/sound.c @ 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 | a66ee70c614c |
children | 5bc3d67ceb24 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
8046 | 4 * Gaim is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
1 | 7 * |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 * | |
22 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
23 #include "internal.h" |
3630 | 24 |
10322 | 25 #include "blist.h" |
26 #include "prefs.h" | |
4561 | 27 #include "sound.h" |
1 | 28 |
5684 | 29 static GaimSoundUiOps *sound_ui_ops = NULL; |
3319 | 30 |
10322 | 31 void |
11642 | 32 gaim_sound_play_file(const char *filename, const GaimAccount *account) |
5684 | 33 { |
11642 | 34 GaimStatus *status; |
35 | |
11652 | 36 if ((account != NULL) && (!gaim_prefs_get_bool("/core/sound/while_away"))) |
11642 | 37 { |
38 status = gaim_account_get_active_status(account); | |
39 if (gaim_status_is_online(status) && !gaim_status_is_available(status)) | |
40 return; | |
41 } | |
4430 | 42 |
5684 | 43 if(sound_ui_ops && sound_ui_ops->play_file) |
44 sound_ui_ops->play_file(filename); | |
1006
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
45 } |
0a4d0ed65e17
[gaim-migrate @ 1016]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
899
diff
changeset
|
46 |
10322 | 47 void |
11642 | 48 gaim_sound_play_event(GaimSoundEventID event, const GaimAccount *account) |
1 | 49 { |
11642 | 50 GaimStatus *status; |
51 | |
11652 | 52 if ((account != NULL) && (!gaim_prefs_get_bool("/core/sound/while_away"))) |
11642 | 53 { |
54 status = gaim_account_get_active_status(account); | |
55 if (gaim_status_is_online(status) && !gaim_status_is_available(status)) | |
56 return; | |
57 } | |
4561 | 58 |
5684 | 59 if(sound_ui_ops && sound_ui_ops->play_event) |
60 sound_ui_ops->play_event(event); | |
4561 | 61 } |
10322 | 62 |
63 void | |
64 gaim_sound_set_ui_ops(GaimSoundUiOps *ops) | |
65 { | |
66 if(sound_ui_ops && sound_ui_ops->uninit) | |
67 sound_ui_ops->uninit(); | |
68 | |
69 sound_ui_ops = ops; | |
70 | |
71 if(sound_ui_ops && sound_ui_ops->init) | |
72 sound_ui_ops->init(); | |
73 } | |
74 | |
75 GaimSoundUiOps * | |
76 gaim_sound_get_ui_ops(void) | |
77 { | |
78 return sound_ui_ops; | |
79 } | |
80 | |
81 void | |
82 gaim_sound_init() | |
83 { | |
84 gaim_prefs_add_none("/core/sound"); | |
85 gaim_prefs_add_bool("/core/sound/while_away", FALSE); | |
86 | |
87 } | |
88 | |
89 void | |
90 gaim_sound_uninit() | |
91 { | |
92 if(sound_ui_ops && sound_ui_ops->uninit) | |
93 sound_ui_ops->uninit(); | |
94 } |