gdbusaddress: Use simpler hash table keys as arrays

We don't really need the lists overhead here, so let's just use the simpler
forms.
This commit is contained in:
Marco Trevisan (Treviño) 2022-12-08 03:33:56 +01:00
parent e733a3db10
commit 5d5d12112b

View File

@ -130,8 +130,8 @@ is_valid_unix (const gchar *address_entry,
GError **error) GError **error)
{ {
gboolean ret; gboolean ret;
GList *keys; char **keys;
GList *l; guint keys_length;
const gchar *path; const gchar *path;
const gchar *dir; const gchar *dir;
const gchar *tmpdir; const gchar *tmpdir;
@ -144,10 +144,10 @@ is_valid_unix (const gchar *address_entry,
tmpdir = NULL; tmpdir = NULL;
abstract = NULL; abstract = NULL;
keys = g_hash_table_get_keys (key_value_pairs); keys = (char **) g_hash_table_get_keys_as_array (key_value_pairs, &keys_length);
for (l = keys; l != NULL; l = l->next) for (guint i = 0; i < keys_length; ++i)
{ {
const gchar *key = l->data; const gchar *key = keys[i];
if (g_strcmp0 (key, "path") == 0) if (g_strcmp0 (key, "path") == 0)
path = g_hash_table_lookup (key_value_pairs, key); path = g_hash_table_lookup (key_value_pairs, key);
else if (g_strcmp0 (key, "dir") == 0) else if (g_strcmp0 (key, "dir") == 0)
@ -191,7 +191,7 @@ is_valid_unix (const gchar *address_entry,
ret = TRUE; ret = TRUE;
out: out:
g_list_free (keys); g_free (keys);
return ret; return ret;
} }
@ -202,8 +202,8 @@ is_valid_nonce_tcp (const gchar *address_entry,
GError **error) GError **error)
{ {
gboolean ret; gboolean ret;
GList *keys; char **keys;
GList *l; guint keys_length;
const gchar *host; const gchar *host;
const gchar *port; const gchar *port;
const gchar *family; const gchar *family;
@ -218,10 +218,10 @@ is_valid_nonce_tcp (const gchar *address_entry,
family = NULL; family = NULL;
nonce_file = NULL; nonce_file = NULL;
keys = g_hash_table_get_keys (key_value_pairs); keys = (char **) g_hash_table_get_keys_as_array (key_value_pairs, &keys_length);
for (l = keys; l != NULL; l = l->next) for (guint i = 0; i < keys_length; ++i)
{ {
const gchar *key = l->data; const gchar *key = keys[i];
if (g_strcmp0 (key, "host") == 0) if (g_strcmp0 (key, "host") == 0)
host = g_hash_table_lookup (key_value_pairs, key); host = g_hash_table_lookup (key_value_pairs, key);
else if (g_strcmp0 (key, "port") == 0) else if (g_strcmp0 (key, "port") == 0)
@ -284,7 +284,7 @@ is_valid_nonce_tcp (const gchar *address_entry,
ret = TRUE; ret = TRUE;
out: out:
g_list_free (keys); g_free (keys);
return ret; return ret;
} }
@ -295,8 +295,8 @@ is_valid_tcp (const gchar *address_entry,
GError **error) GError **error)
{ {
gboolean ret; gboolean ret;
GList *keys; char **keys;
GList *l; guint keys_length;
const gchar *host; const gchar *host;
const gchar *port; const gchar *port;
const gchar *family; const gchar *family;
@ -309,10 +309,10 @@ is_valid_tcp (const gchar *address_entry,
port = NULL; port = NULL;
family = NULL; family = NULL;
keys = g_hash_table_get_keys (key_value_pairs); keys = (char **) g_hash_table_get_keys_as_array (key_value_pairs, &keys_length);
for (l = keys; l != NULL; l = l->next) for (guint i = 0; i < keys_length; ++i)
{ {
const gchar *key = l->data; const gchar *key = keys[i];
if (g_strcmp0 (key, "host") == 0) if (g_strcmp0 (key, "host") == 0)
host = g_hash_table_lookup (key_value_pairs, key); host = g_hash_table_lookup (key_value_pairs, key);
else if (g_strcmp0 (key, "port") == 0) else if (g_strcmp0 (key, "port") == 0)
@ -363,7 +363,7 @@ is_valid_tcp (const gchar *address_entry,
ret= TRUE; ret= TRUE;
out: out:
g_list_free (keys); g_free (keys);
return ret; return ret;
} }