[libgudev/wip/muktupavels/current-tags: 2/2] device: cache tags on device creation
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgudev/wip/muktupavels/current-tags: 2/2] device: cache tags on device creation
- Date: Tue, 21 Jun 2022 16:17:36 +0000 (UTC)
commit 3f73053b513afb9f6dd03a325c896605793cae39
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Jun 21 19:01:24 2022 +0300
device: cache tags on device creation
GUdevDevice contains snapshot of information when device object
was created. Cache tags on device creation to follow this rule.
gudev/gudevdevice.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/gudev/gudevdevice.c b/gudev/gudevdevice.c
index 02d7e78..b8060a6 100644
--- a/gudev/gudevdevice.c
+++ b/gudev/gudevdevice.c
@@ -121,6 +121,21 @@ g_udev_device_init (GUdevDevice *device)
device->priv = g_udev_device_get_instance_private (device);
}
+static void
+fetch_get_tags (GUdevDevice *device)
+{
+ struct udev_list_entry *l;
+ GPtrArray *p;
+
+ p = g_ptr_array_new ();
+ for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next
(l))
+ {
+ g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
+ }
+ g_ptr_array_add (p, NULL);
+ device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE);
+}
+
static void
fetch_current_tags (GUdevDevice *device)
{
@@ -144,6 +159,7 @@ _g_udev_device_new (struct udev_device *udevice)
device = G_UDEV_DEVICE (g_object_new (G_UDEV_TYPE_DEVICE, NULL));
device->priv->udevice = udev_device_ref (udevice);
+ fetch_get_tags (device);
fetch_current_tags (device);
return device;
@@ -1204,23 +1220,8 @@ g_udev_device_get_sysfs_attr_as_strv_uncached (GUdevDevice *device,
const gchar* const *
g_udev_device_get_tags (GUdevDevice *device)
{
- struct udev_list_entry *l;
- GPtrArray *p;
-
g_return_val_if_fail (G_UDEV_IS_DEVICE (device), NULL);
- if (device->priv->tags != NULL)
- goto out;
-
- p = g_ptr_array_new ();
- for (l = udev_device_get_tags_list_entry (device->priv->udevice); l != NULL; l = udev_list_entry_get_next
(l))
- {
- g_ptr_array_add (p, g_strdup (udev_list_entry_get_name (l)));
- }
- g_ptr_array_add (p, NULL);
- device->priv->tags = (gchar **) g_ptr_array_free (p, FALSE);
-
- out:
return (const gchar * const *) device->priv->tags;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]