From e1da2d4f706f998864c479d8998b81ca3f67f6fa Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 19 May 2023 10:11:48 -0700 Subject: [PATCH] libsysprof-analyze: use GRefString for SysprofMountDevice We will end up creating a lot of these, and it's nice to at least be able to share the strings even if we can't always share the objects themselves. --- src/libsysprof-analyze/sysprof-document.c | 12 ++- .../sysprof-mount-device-private.h | 10 +-- src/libsysprof-analyze/sysprof-mount-device.c | 89 +++++-------------- 3 files changed, 28 insertions(+), 83 deletions(-) diff --git a/src/libsysprof-analyze/sysprof-document.c b/src/libsysprof-analyze/sysprof-document.c index fd3b28a5..d07ebd7a 100644 --- a/src/libsysprof-analyze/sysprof-document.c +++ b/src/libsysprof-analyze/sysprof-document.c @@ -279,9 +279,8 @@ sysprof_document_load_mounts (SysprofDocument *self) line_reader_init (&reader, (char *)contents, contents_len); while ((line = line_reader_next (&reader, &line_len))) { - g_autoptr(SysprofMountDevice) mount_device = NULL; - g_auto(GStrv) parts = NULL; g_autofree char *subvol = NULL; + g_auto(GStrv) parts = NULL; const char *filesystem; const char *mountpoint; const char *device; @@ -322,11 +321,10 @@ sysprof_document_load_mounts (SysprofDocument *self) } } - mount_device = sysprof_mount_device_new (); - sysprof_mount_device_set_id (mount_device, device); - sysprof_mount_device_set_mount_point (mount_device, mountpoint); - sysprof_mount_device_set_subvolume (mount_device, subvol); - sysprof_mount_namespace_add_device (self->mount_namespace, g_steal_pointer (&mount_device)); + sysprof_mount_namespace_add_device (self->mount_namespace, + sysprof_mount_device_new (sysprof_strings_get (self->strings, device), + sysprof_strings_get (self->strings, mountpoint), + sysprof_strings_get (self->strings, subvol))); } } diff --git a/src/libsysprof-analyze/sysprof-mount-device-private.h b/src/libsysprof-analyze/sysprof-mount-device-private.h index db9e4f5a..12b882c9 100644 --- a/src/libsysprof-analyze/sysprof-mount-device-private.h +++ b/src/libsysprof-analyze/sysprof-mount-device-private.h @@ -28,15 +28,11 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (SysprofMountDevice, sysprof_mount_device, SYSPROF, MOUNT_DEVICE, GObject) -SysprofMountDevice *sysprof_mount_device_new (void); +SysprofMountDevice *sysprof_mount_device_new (GRefString *id, + GRefString *mount_point, + GRefString *subvolume); const char *sysprof_mount_device_get_id (SysprofMountDevice *self); -void sysprof_mount_device_set_id (SysprofMountDevice *self, - const char *id); const char *sysprof_mount_device_get_mount_point (SysprofMountDevice *self); -void sysprof_mount_device_set_mount_point (SysprofMountDevice *self, - const char *mount_point); const char *sysprof_mount_device_get_subvolume (SysprofMountDevice *self); -void sysprof_mount_device_set_subvolume (SysprofMountDevice *self, - const char *subvolume); G_END_DECLS diff --git a/src/libsysprof-analyze/sysprof-mount-device.c b/src/libsysprof-analyze/sysprof-mount-device.c index 1d08dd44..59062bc2 100644 --- a/src/libsysprof-analyze/sysprof-mount-device.c +++ b/src/libsysprof-analyze/sysprof-mount-device.c @@ -25,9 +25,9 @@ struct _SysprofMountDevice { GObject parent_instance; - char *id; - char *mount_point; - char *subvolume; + GRefString *id; + GRefString *mount_point; + GRefString *subvolume; }; enum { @@ -47,9 +47,9 @@ sysprof_mount_device_finalize (GObject *object) { SysprofMountDevice *self = (SysprofMountDevice *)object; - g_clear_pointer (&self->id, g_free); - g_clear_pointer (&self->mount_point, g_free); - g_clear_pointer (&self->subvolume, g_free); + g_clear_pointer (&self->id, g_ref_string_release); + g_clear_pointer (&self->mount_point, g_ref_string_release); + g_clear_pointer (&self->subvolume, g_ref_string_release); G_OBJECT_CLASS (sysprof_mount_device_parent_class)->finalize (object); } @@ -81,33 +81,6 @@ sysprof_mount_device_get_property (GObject *object, } } -static void -sysprof_mount_device_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofMountDevice *self = SYSPROF_MOUNT_DEVICE (object); - - switch (prop_id) - { - case PROP_ID: - sysprof_mount_device_set_id (self, g_value_get_string (value)); - break; - - case PROP_MOUNT_POINT: - sysprof_mount_device_set_mount_point (self, g_value_get_string (value)); - break; - - case PROP_SUBVOLUME: - sysprof_mount_device_set_subvolume (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - static void sysprof_mount_device_class_init (SysprofMountDeviceClass *klass) { @@ -115,22 +88,21 @@ sysprof_mount_device_class_init (SysprofMountDeviceClass *klass) object_class->finalize = sysprof_mount_device_finalize; object_class->get_property = sysprof_mount_device_get_property; - object_class->set_property = sysprof_mount_device_set_property; properties [PROP_ID] = g_param_spec_string ("id", NULL, NULL, NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); properties [PROP_MOUNT_POINT] = g_param_spec_string ("mount-point", NULL, NULL, NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); properties [PROP_SUBVOLUME] = g_param_spec_string ("subvolume", NULL, NULL, NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); g_object_class_install_properties (object_class, N_PROPS, properties); } @@ -141,9 +113,18 @@ sysprof_mount_device_init (SysprofMountDevice *self) } SysprofMountDevice * -sysprof_mount_device_new (void) +sysprof_mount_device_new (GRefString *id, + GRefString *mount_point, + GRefString *subvolume) { - return g_object_new (SYSPROF_TYPE_MOUNT_DEVICE, NULL); + SysprofMountDevice *self; + + self = g_object_new (SYSPROF_TYPE_MOUNT_DEVICE, NULL); + self->id = id; + self->mount_point = mount_point; + self->subvolume = subvolume; + + return g_steal_pointer (&self); } const char * @@ -154,16 +135,6 @@ sysprof_mount_device_get_id (SysprofMountDevice *self) return self->id; } -void -sysprof_mount_device_set_id (SysprofMountDevice *self, - const char *id) -{ - g_return_if_fail (SYSPROF_IS_MOUNT_DEVICE (self)); - - if (g_set_str (&self->id, id)) - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ID]); -} - const char * sysprof_mount_device_get_mount_point (SysprofMountDevice *self) { @@ -172,16 +143,6 @@ sysprof_mount_device_get_mount_point (SysprofMountDevice *self) return self->mount_point; } -void -sysprof_mount_device_set_mount_point (SysprofMountDevice *self, - const char *mount_point) -{ - g_return_if_fail (SYSPROF_IS_MOUNT_DEVICE (self)); - - if (g_set_str (&self->mount_point, mount_point)) - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MOUNT_POINT]); -} - const char * sysprof_mount_device_get_subvolume (SysprofMountDevice *self) { @@ -189,13 +150,3 @@ sysprof_mount_device_get_subvolume (SysprofMountDevice *self) return self->subvolume; } - -void -sysprof_mount_device_set_subvolume (SysprofMountDevice *self, - const char *subvolume) -{ - g_return_if_fail (SYSPROF_IS_MOUNT_DEVICE (self)); - - if (g_set_str (&self->subvolume, subvolume)) - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SUBVOLUME]); -}