From 07756025745493b1999f7c04b5e826c50b73b42d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 27 Dec 2017 09:40:59 +0100 Subject: device: don't keep a clone of the type-description for each device instance Instead, intern the string and cache it in the NMDeviceClass instance. It anyway depends entirely on the GObject type (name), hence it should also be cached at the type. --- src/devices/nm-device.c | 15 +++++++++------ src/devices/nm-device.h | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 8168957dd4..ce144c3b08 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -269,7 +269,6 @@ typedef struct _NMDevicePrivate { int ip_ifindex; NMDeviceType type; char * type_desc; - char * type_description; NMLinkType link_type; NMDeviceCapabilities capabilities; char * driver; @@ -1988,18 +1987,23 @@ nm_device_get_type_description (NMDevice *self) static const char * get_type_description (NMDevice *self) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDeviceClass *klass; - if (!priv->type_description) { + nm_assert (NM_IS_DEVICE (self)); + + klass = NM_DEVICE_GET_CLASS (self); + if (G_UNLIKELY (!klass->default_type_description)) { const char *typename; + gs_free char *s = NULL; typename = G_OBJECT_TYPE_NAME (self); if (g_str_has_prefix (typename, "NMDevice")) typename += 8; - priv->type_description = g_ascii_strdown (typename, -1); + s = g_ascii_strdown (typename, -1); + klass->default_type_description = g_intern_string (s); } - return priv->type_description; + return klass->default_type_description; } gboolean @@ -14581,7 +14585,6 @@ finalize (GObject *object) g_free (priv->driver_version); g_free (priv->firmware_version); g_free (priv->type_desc); - g_free (priv->type_description); g_free (priv->dhcp_anycast_address); g_free (priv->current_stable_id); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index abb2420c14..8c823bab4d 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -192,6 +192,8 @@ typedef enum { /*< skip >*/ typedef struct { NMExportedObjectClass parent; + const char *default_type_description; + const char *connection_type; const NMLinkType *link_types; -- cgit v1.2.1