[gtk+] XSettingsList is now a typedef for GHashTable.
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] XSettingsList is now a typedef for GHashTable.
- Date: Sun, 27 Jan 2013 00:08:38 +0000 (UTC)
commit ce6b77c25ba731447747aad6cc0bc39859348a3a
Author: John Lindgren <john lindgren aol com>
Date: Sat Jan 26 16:47:09 2013 -0500
XSettingsList is now a typedef for GHashTable.
https://bugzilla.gnome.org/show_bug.cgi?id=692605
gdk/x11/xsettings-client.c | 59 +++++++------------
gdk/x11/xsettings-common.c | 133 ++++----------------------------------------
gdk/x11/xsettings-common.h | 16 +----
3 files changed, 37 insertions(+), 171 deletions(-)
---
diff --git a/gdk/x11/xsettings-client.c b/gdk/x11/xsettings-client.c
index 103843d..fb3dca3 100644
--- a/gdk/x11/xsettings-client.c
+++ b/gdk/x11/xsettings-client.c
@@ -56,51 +56,36 @@ static void
notify_changes (XSettingsClient *client,
XSettingsList *old_list)
{
- XSettingsList *old_iter = old_list;
- XSettingsList *new_iter = client->settings;
+ GHashTableIter iter;
+ XSettingsSetting *setting, *old_setting;
if (!client->notify)
return;
- while (old_iter || new_iter)
+ if (client->settings != NULL)
{
- int cmp;
-
- if (old_iter && new_iter)
- cmp = strcmp (old_iter->setting->name, new_iter->setting->name);
- else if (old_iter)
- cmp = -1;
- else
- cmp = 1;
-
- if (cmp < 0)
- {
- client->notify (old_iter->setting->name,
- XSETTINGS_ACTION_DELETED,
- NULL,
- client->cb_data);
- }
- else if (cmp == 0)
+ g_hash_table_iter_init (&iter, client->settings);
+ while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &setting))
{
- if (!xsettings_setting_equal (old_iter->setting,
- new_iter->setting))
- client->notify (old_iter->setting->name,
- XSETTINGS_ACTION_CHANGED,
- new_iter->setting,
- client->cb_data);
- }
- else
- {
- client->notify (new_iter->setting->name,
- XSETTINGS_ACTION_NEW,
- new_iter->setting,
- client->cb_data);
+ old_setting = xsettings_list_lookup (old_list, setting->name);
+
+ if (old_setting == NULL)
+ client->notify (setting->name, XSETTINGS_ACTION_NEW, setting, client->cb_data);
+ else if (!xsettings_setting_equal (setting, old_setting))
+ client->notify (setting->name, XSETTINGS_ACTION_CHANGED, setting, client->cb_data);
+
+ /* remove setting from old_list */
+ if (old_setting != NULL)
+ g_hash_table_remove (old_list, setting->name);
}
+ }
- if (old_iter)
- old_iter = old_iter->next;
- if (new_iter)
- new_iter = new_iter->next;
+ if (old_list != NULL)
+ {
+ /* old_list now contains only deleted settings */
+ g_hash_table_iter_init (&iter, old_list);
+ while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &old_setting))
+ client->notify (old_setting->name, XSETTINGS_ACTION_DELETED, NULL, client->cb_data);
}
}
diff --git a/gdk/x11/xsettings-common.c b/gdk/x11/xsettings-common.c
index cc3a8d0..6f66a40 100644
--- a/gdk/x11/xsettings-common.c
+++ b/gdk/x11/xsettings-common.c
@@ -80,45 +80,6 @@ xsettings_setting_copy (XSettingsSetting *setting)
return NULL;
}
-XSettingsList *
-xsettings_list_copy (XSettingsList *list)
-{
- XSettingsList *new = NULL;
- XSettingsList *old_iter = list;
- XSettingsList *new_iter = NULL;
-
- while (old_iter)
- {
- XSettingsList *new_node;
-
- new_node = malloc (sizeof *new_node);
- if (!new_node)
- goto error;
-
- new_node->setting = xsettings_setting_copy (old_iter->setting);
- if (!new_node->setting)
- {
- free (new_node);
- goto error;
- }
-
- if (new_iter)
- new_iter->next = new_node;
- else
- new = new_node;
-
- new_iter = new_node;
-
- old_iter = old_iter->next;
- }
-
- return new;
-
- error:
- xsettings_list_free (new);
- return NULL;
-}
-
int
xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b)
@@ -160,103 +121,33 @@ xsettings_setting_free (XSettingsSetting *setting)
void
xsettings_list_free (XSettingsList *list)
{
- while (list)
- {
- XSettingsList *next = list->next;
-
- xsettings_setting_free (list->setting);
- free (list);
-
- list = next;
- }
+ if (list != NULL)
+ g_hash_table_destroy (list);
}
XSettingsResult
xsettings_list_insert (XSettingsList **list,
XSettingsSetting *setting)
{
- XSettingsList *node;
- XSettingsList *iter;
- XSettingsList *last = NULL;
-
- node = malloc (sizeof *node);
- if (!node)
- return XSETTINGS_NO_MEM;
- node->setting = setting;
+ if (*list == NULL)
+ *list = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ (GDestroyNotify) xsettings_setting_free);
- iter = *list;
- while (iter)
- {
- int cmp = strcmp (setting->name, iter->setting->name);
+ if (g_hash_table_lookup (*list, setting->name) != NULL)
+ return XSETTINGS_DUPLICATE_ENTRY;
- if (cmp < 0)
- break;
- else if (cmp == 0)
- {
- free (node);
- return XSETTINGS_DUPLICATE_ENTRY;
- }
-
- last = iter;
- iter = iter->next;
- }
-
- if (last)
- last->next = node;
- else
- *list = node;
-
- node->next = iter;
-
+ g_hash_table_insert (*list, setting->name, setting);
return XSETTINGS_SUCCESS;
}
-XSettingsResult
-xsettings_list_delete (XSettingsList **list,
- const char *name)
-{
- XSettingsList *iter;
- XSettingsList *last = NULL;
-
- iter = *list;
- while (iter)
- {
- if (strcmp (name, iter->setting->name) == 0)
- {
- if (last)
- last->next = iter->next;
- else
- *list = iter->next;
-
- xsettings_setting_free (iter->setting);
- free (iter);
-
- return XSETTINGS_SUCCESS;
- }
-
- last = iter;
- iter = iter->next;
- }
-
- return XSETTINGS_FAILED;
-}
-
XSettingsSetting *
xsettings_list_lookup (XSettingsList *list,
const char *name)
{
- XSettingsList *iter;
-
- iter = list;
- while (iter)
- {
- if (strcmp (name, iter->setting->name) == 0)
- return iter->setting;
-
- iter = iter->next;
- }
-
- return NULL;
+ if (list == NULL)
+ return NULL;
+
+ return g_hash_table_lookup (list, name);
}
char
diff --git a/gdk/x11/xsettings-common.h b/gdk/x11/xsettings-common.h
index dcd87f4..0577db5 100644
--- a/gdk/x11/xsettings-common.h
+++ b/gdk/x11/xsettings-common.h
@@ -23,7 +23,8 @@
#ifndef XSETTINGS_COMMON_H
#define XSETTINGS_COMMON_H
-#include <unistd.h>
+#include <glib.h>
+#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
@@ -39,8 +40,6 @@ extern "C" {
#define xsettings_client_set_grab_func _gdk_x11_xsettings_client_set_grab_func
#define xsettings_client_set_ungrab_func _gdk_x11_xsettings_client_set_ungrab_func
#define xsettings_client_process_event _gdk_x11_xsettings_client_process_event
-#define xsettings_list_copy _gdk_x11_xsettings_list_copy
-#define xsettings_list_delete _gdk_x11_xsettings_list_delete
#define xsettings_list_free _gdk_x11_xsettings_list_free
#define xsettings_list_insert _gdk_x11_xsettings_list_insert
#define xsettings_list_lookup _gdk_x11_xsettings_list_lookup
@@ -48,10 +47,10 @@ extern "C" {
#define xsettings_setting_equal _gdk_x11_xsettings_setting_equal
#define xsettings_setting_free _gdk_x11_xsettings_setting_free
+typedef GHashTable XSettingsList;
typedef struct _XSettingsBuffer XSettingsBuffer;
typedef struct _XSettingsColor XSettingsColor;
-typedef struct _XSettingsList XSettingsList;
typedef struct _XSettingsSetting XSettingsSetting;
/* Types of settings possible. Enum values correspond to
@@ -87,12 +86,6 @@ struct _XSettingsColor
unsigned short red, green, blue, alpha;
};
-struct _XSettingsList
-{
- XSettingsSetting *setting;
- XSettingsList *next;
-};
-
struct _XSettingsSetting
{
char *name;
@@ -113,13 +106,10 @@ int xsettings_setting_equal (XSettingsSetting *setting_a,
XSettingsSetting *setting_b);
void xsettings_list_free (XSettingsList *list);
-XSettingsList *xsettings_list_copy (XSettingsList *list);
XSettingsResult xsettings_list_insert (XSettingsList **list,
XSettingsSetting *setting);
XSettingsSetting *xsettings_list_lookup (XSettingsList *list,
const char *name);
-XSettingsResult xsettings_list_delete (XSettingsList **list,
- const char *name);
char xsettings_byte_order (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]