mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
Use hash tables as sets in various places
Where we were already treating GHashTables as sets, modify them to use the set-specific APIs g_hash_table_add() and g_hash_table_contains(), to make that usage more obvious and less prone to being broken. Heavily based on patches by Garrett Regier <garrettregier@gmail.com>. Signed-off-by: Philip Withnall <withnall@endlessm.com> https://bugzilla.gnome.org/show_bug.cgi?id=749371
This commit is contained in:
@@ -309,7 +309,7 @@ print_names (GDBusConnection *c,
|
||||
}
|
||||
g_variant_get (result, "(as)", &iter);
|
||||
while (g_variant_iter_loop (iter, "s", &str))
|
||||
g_hash_table_insert (name_set, g_strdup (str), NULL);
|
||||
g_hash_table_add (name_set, g_strdup (str));
|
||||
g_variant_iter_free (iter);
|
||||
g_variant_unref (result);
|
||||
|
||||
@@ -333,7 +333,7 @@ print_names (GDBusConnection *c,
|
||||
}
|
||||
g_variant_get (result, "(as)", &iter);
|
||||
while (g_variant_iter_loop (iter, "s", &str))
|
||||
g_hash_table_insert (name_set, g_strdup (str), NULL);
|
||||
g_hash_table_add (name_set, g_strdup (str));
|
||||
g_variant_iter_free (iter);
|
||||
g_variant_unref (result);
|
||||
|
||||
|
@@ -635,7 +635,7 @@ g_dbus_connection_dispose (GObject *object)
|
||||
else
|
||||
{
|
||||
if (alive_connections != NULL)
|
||||
g_warn_if_fail (g_hash_table_lookup (alive_connections, connection) == NULL);
|
||||
g_warn_if_fail (!g_hash_table_contains (alive_connections, connection));
|
||||
}
|
||||
CONNECTION_UNLOCK (connection);
|
||||
G_UNLOCK (message_bus_lock);
|
||||
@@ -2226,7 +2226,7 @@ on_worker_message_received (GDBusWorker *worker,
|
||||
gboolean alive;
|
||||
|
||||
G_LOCK (message_bus_lock);
|
||||
alive = (g_hash_table_lookup (alive_connections, user_data) != NULL);
|
||||
alive = g_hash_table_contains (alive_connections, user_data);
|
||||
if (!alive)
|
||||
{
|
||||
G_UNLOCK (message_bus_lock);
|
||||
@@ -2324,7 +2324,7 @@ on_worker_message_about_to_be_sent (GDBusWorker *worker,
|
||||
gboolean alive;
|
||||
|
||||
G_LOCK (message_bus_lock);
|
||||
alive = (g_hash_table_lookup (alive_connections, user_data) != NULL);
|
||||
alive = g_hash_table_contains (alive_connections, user_data);
|
||||
if (!alive)
|
||||
{
|
||||
G_UNLOCK (message_bus_lock);
|
||||
@@ -2397,7 +2397,7 @@ on_worker_closed (GDBusWorker *worker,
|
||||
guint old_atomic_flags;
|
||||
|
||||
G_LOCK (message_bus_lock);
|
||||
alive = (g_hash_table_lookup (alive_connections, user_data) != NULL);
|
||||
alive = g_hash_table_contains (alive_connections, user_data);
|
||||
if (!alive)
|
||||
{
|
||||
G_UNLOCK (message_bus_lock);
|
||||
@@ -2572,7 +2572,7 @@ initable_init (GInitable *initable,
|
||||
G_LOCK (message_bus_lock);
|
||||
if (alive_connections == NULL)
|
||||
alive_connections = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
g_hash_table_insert (alive_connections, connection, connection);
|
||||
g_hash_table_add (alive_connections, connection);
|
||||
G_UNLOCK (message_bus_lock);
|
||||
|
||||
connection->worker = _g_dbus_worker_new (connection->stream,
|
||||
@@ -4708,8 +4708,8 @@ maybe_add_path (const gchar *path, gsize path_len, const gchar *object_path, GHa
|
||||
else
|
||||
s = g_strdup (begin);
|
||||
|
||||
if (g_hash_table_lookup (set, s) == NULL)
|
||||
g_hash_table_insert (set, s, GUINT_TO_POINTER (1));
|
||||
if (!g_hash_table_contains (set, s))
|
||||
g_hash_table_add (set, s);
|
||||
else
|
||||
g_free (s);
|
||||
}
|
||||
|
@@ -202,14 +202,14 @@ g_io_module_scope_block (GIOModuleScope *scope,
|
||||
g_return_if_fail (basename != NULL);
|
||||
|
||||
key = g_strdup (basename);
|
||||
g_hash_table_insert (scope->basenames, key, key);
|
||||
g_hash_table_add (scope->basenames, key);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_g_io_module_scope_contains (GIOModuleScope *scope,
|
||||
const gchar *basename)
|
||||
{
|
||||
return g_hash_table_lookup (scope->basenames, basename) ? TRUE : FALSE;
|
||||
return g_hash_table_contains (scope->basenames, basename);
|
||||
}
|
||||
|
||||
struct _GIOModule {
|
||||
|
@@ -785,18 +785,21 @@ g_settings_schema_source_list_schemas (GSettingsSchemaSource *source,
|
||||
|
||||
for (i = 0; list[i]; i++)
|
||||
{
|
||||
if (!g_hash_table_lookup (single, list[i]) &&
|
||||
!g_hash_table_lookup (reloc, list[i]))
|
||||
if (!g_hash_table_contains (single, list[i]) &&
|
||||
!g_hash_table_contains (reloc, list[i]))
|
||||
{
|
||||
gchar *schema;
|
||||
GvdbTable *table;
|
||||
|
||||
schema = g_strdup (list[i]);
|
||||
|
||||
table = gvdb_table_get_table (s->table, list[i]);
|
||||
g_assert (table != NULL);
|
||||
|
||||
if (gvdb_table_has_value (table, ".path"))
|
||||
g_hash_table_insert (single, g_strdup (list[i]), NULL);
|
||||
g_hash_table_add (single, schema);
|
||||
else
|
||||
g_hash_table_insert (reloc, g_strdup (list[i]), NULL);
|
||||
g_hash_table_add (reloc, schema);
|
||||
|
||||
gvdb_table_unref (table);
|
||||
}
|
||||
|
Reference in New Issue
Block a user