summaryrefslogtreecommitdiff
path: root/libmate-panel-applet
diff options
context:
space:
mode:
authorColomban Wendling <[email protected]>2023-11-15 14:45:37 +0100
committerLuke from DC <[email protected]>2023-11-21 20:19:58 +0000
commite59c6d0276832bf8201561f71718daeca2465360 (patch)
tree0008a84964240aa65a983453c299468576d618fb /libmate-panel-applet
parentec5938e508526a70962e770ddd811f020951d1e8 (diff)
downloadmate-panel-e59c6d0276832bf8201561f71718daeca2465360.tar.bz2
mate-panel-e59c6d0276832bf8201561f71718daeca2465360.tar.xz
Optimize mate_panel_applet_settings_get_g*list()
- Build the list in reverse order, then reverse the result. This is useful because GS?List are list nodes, not containers of nodes, and thus don't contain a pointer to the list's end, meaning to append one has to walk the entire list to find the end each time. To avoid this we use the common idiom of prepending to the list (which is cheap, as it's adding a node before the given one), and then reversing the resulting list to get back the original order. - Avoid unnecessary memory copy by stealing the GStrv's members. We get the array as a copy, so we can simply steal the members and free the container array only, saving a copy for each member.
Diffstat (limited to 'libmate-panel-applet')
-rw-r--r--libmate-panel-applet/mate-panel-applet-gsettings.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/libmate-panel-applet/mate-panel-applet-gsettings.c b/libmate-panel-applet/mate-panel-applet-gsettings.c
index 4679dc6d..a4bd3db1 100644
--- a/libmate-panel-applet/mate-panel-applet-gsettings.c
+++ b/libmate-panel-applet/mate-panel-applet-gsettings.c
@@ -134,15 +134,15 @@ mate_panel_applet_settings_get_glist (GSettings *settings, gchar *key)
{
gchar **array;
GList *list = NULL;
- gint i;
+
array = g_settings_get_strv (settings, key);
if (array != NULL) {
- for (i = 0; array[i]; i++) {
- list = g_list_append (list, g_strdup (array[i]));
+ for (gint i = 0; array[i]; i++) {
+ list = g_list_prepend (list, array[i]);
}
+ g_free (array);
}
- g_strfreev (array);
- return list;
+ return g_list_reverse (list);
}
void
@@ -163,15 +163,15 @@ mate_panel_applet_settings_get_gslist (GSettings *settings, gchar *key)
{
gchar **array;
GSList *list = NULL;
- gint i;
+
array = g_settings_get_strv (settings, key);
if (array != NULL) {
- for (i = 0; array[i]; i++) {
- list = g_slist_append (list, g_strdup (array[i]));
+ for (gint i = 0; array[i]; i++) {
+ list = g_slist_prepend (list, array[i]);
}
+ g_free (array);
}
- g_strfreev (array);
- return list;
+ return g_slist_reverse (list);
}
void