mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
gdbusmessage: Get message headers keys as arrays
We eventually need to return them as an array anyways. Sadly we can't just reuse such memory because each element is a pointer and not a guchar, but still we can be cheaper in various operations.
This commit is contained in:
parent
1e699edf0e
commit
0e56d2f5db
@ -1094,24 +1094,27 @@ g_dbus_message_set_header (GDBusMessage *message,
|
|||||||
guchar *
|
guchar *
|
||||||
g_dbus_message_get_header_fields (GDBusMessage *message)
|
g_dbus_message_get_header_fields (GDBusMessage *message)
|
||||||
{
|
{
|
||||||
GList *keys;
|
GPtrArray *keys;
|
||||||
guchar *ret;
|
GArray *array;
|
||||||
guint num_keys;
|
|
||||||
GList *l;
|
|
||||||
guint n;
|
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL);
|
||||||
|
|
||||||
keys = g_hash_table_get_keys (message->headers);
|
keys = g_hash_table_get_keys_as_ptr_array (message->headers);
|
||||||
num_keys = g_list_length (keys);
|
array = g_array_sized_new (FALSE, FALSE, sizeof (guchar), keys->len + 1);
|
||||||
ret = g_new (guchar, num_keys + 1);
|
|
||||||
for (l = keys, n = 0; l != NULL; l = l->next, n++)
|
|
||||||
ret[n] = GPOINTER_TO_UINT (l->data);
|
|
||||||
g_assert (n == num_keys);
|
|
||||||
ret[n] = G_DBUS_MESSAGE_HEADER_FIELD_INVALID;
|
|
||||||
g_list_free (keys);
|
|
||||||
|
|
||||||
return ret;
|
for (guint i = 0; i < keys->len; ++i)
|
||||||
|
{
|
||||||
|
guchar val = GPOINTER_TO_UINT (g_ptr_array_index (keys, i));
|
||||||
|
g_array_append_val (array, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_assert (array->len == keys->len);
|
||||||
|
g_clear_pointer (&keys, g_ptr_array_unref);
|
||||||
|
|
||||||
|
guchar invalid_field = G_DBUS_MESSAGE_HEADER_FIELD_INVALID;
|
||||||
|
g_array_append_val (array, invalid_field);
|
||||||
|
|
||||||
|
return (guchar *) g_array_free (array, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user