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 5d5d12112b
commit 1e699edf0e

View File

@ -130,24 +130,22 @@ is_valid_unix (const gchar *address_entry,
GError **error) GError **error)
{ {
gboolean ret; gboolean ret;
char **keys; GPtrArray *keys;
guint keys_length;
const gchar *path; const gchar *path;
const gchar *dir; const gchar *dir;
const gchar *tmpdir; const gchar *tmpdir;
const gchar *abstract; const gchar *abstract;
ret = FALSE; ret = FALSE;
keys = NULL;
path = NULL; path = NULL;
dir = NULL; dir = NULL;
tmpdir = NULL; tmpdir = NULL;
abstract = NULL; abstract = NULL;
keys = (char **) g_hash_table_get_keys_as_array (key_value_pairs, &keys_length); keys = g_hash_table_get_keys_as_ptr_array (key_value_pairs);
for (guint i = 0; i < keys_length; ++i) for (guint i = 0; i < keys->len; ++i)
{ {
const gchar *key = keys[i]; const gchar *key = g_ptr_array_index (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 +189,7 @@ is_valid_unix (const gchar *address_entry,
ret = TRUE; ret = TRUE;
out: out:
g_free (keys); g_ptr_array_unref (keys);
return ret; return ret;
} }
@ -202,8 +200,7 @@ is_valid_nonce_tcp (const gchar *address_entry,
GError **error) GError **error)
{ {
gboolean ret; gboolean ret;
char **keys; GPtrArray *keys;
guint keys_length;
const gchar *host; const gchar *host;
const gchar *port; const gchar *port;
const gchar *family; const gchar *family;
@ -212,16 +209,15 @@ is_valid_nonce_tcp (const gchar *address_entry,
gchar *endp; gchar *endp;
ret = FALSE; ret = FALSE;
keys = NULL;
host = NULL; host = NULL;
port = NULL; port = NULL;
family = NULL; family = NULL;
nonce_file = NULL; nonce_file = NULL;
keys = (char **) g_hash_table_get_keys_as_array (key_value_pairs, &keys_length); keys = g_hash_table_get_keys_as_ptr_array (key_value_pairs);
for (guint i = 0; i < keys_length; ++i) for (guint i = 0; i < keys->len; ++i)
{ {
const gchar *key = keys[i]; const gchar *key = g_ptr_array_index (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 +280,7 @@ is_valid_nonce_tcp (const gchar *address_entry,
ret = TRUE; ret = TRUE;
out: out:
g_free (keys); g_ptr_array_unref (keys);
return ret; return ret;
} }
@ -295,8 +291,7 @@ is_valid_tcp (const gchar *address_entry,
GError **error) GError **error)
{ {
gboolean ret; gboolean ret;
char **keys; GPtrArray *keys;
guint keys_length;
const gchar *host; const gchar *host;
const gchar *port; const gchar *port;
const gchar *family; const gchar *family;
@ -304,15 +299,14 @@ is_valid_tcp (const gchar *address_entry,
gchar *endp; gchar *endp;
ret = FALSE; ret = FALSE;
keys = NULL;
host = NULL; host = NULL;
port = NULL; port = NULL;
family = NULL; family = NULL;
keys = (char **) g_hash_table_get_keys_as_array (key_value_pairs, &keys_length); keys = g_hash_table_get_keys_as_ptr_array (key_value_pairs);
for (guint i = 0; i < keys_length; ++i) for (guint i = 0; i < keys->len; ++i)
{ {
const gchar *key = keys[i]; const gchar *key = g_ptr_array_index (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 +357,7 @@ is_valid_tcp (const gchar *address_entry,
ret= TRUE; ret= TRUE;
out: out:
g_free (keys); g_ptr_array_unref (keys);
return ret; return ret;
} }