summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-12-07 17:05:12 +0100
committerThomas Haller <thaller@redhat.com>2015-12-07 19:30:11 +0100
commit04c70c76bccf86a5870d957c35d4cff69ae5e558 (patch)
tree076e7a12409710cb80269c700626ed9627696b30
parent2077dee58203d0f41544c156649dc75b491284c0 (diff)
device: cache pointer to private-data in NMDevice structure
We often lookup the private data and retrieve it via NM_DEVICE_GET_PRIVATE(), which in turn calls G_TYPE_INSTANCE_GET_PRIVATE(). Instead cache the pointer to the private data. There are up- and downsides: - requries additional sizeof(gpointer) bytes for each NMDevice. + retrieving the private pointer will be slightly faster. + easier debugging in gdb as it is currently often a pain to retrieve the private data. But most importantly, the allows to change our common pattern to first cache the private data in a variable @priv. That is often cumbersome to write, especially for short functions. This change gives us a choice to use self->priv directly. Such a change should not be aimed for every class. Instead it makes mostly sense for NMDevice, where it pays off better due to the class' size and ubiquitous use. https://mail.gnome.org/archives/networkmanager-list/2015-December/msg00017.html
-rw-r--r--src/devices/nm-device.c10
-rw-r--r--src/devices/nm-device.h5
2 files changed, 12 insertions, 3 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 1d31224bbc..3d4fb7b041 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -78,7 +78,7 @@ static void nm_device_start_ip_check (NMDevice *self);
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT)
-#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
+#define NM_DEVICE_GET_PRIVATE(o) ((o)->priv)
enum {
STATE_CHANGED,
@@ -190,7 +190,7 @@ typedef struct {
int ifindex;
} DeleteOnDeactivateData;
-typedef struct {
+typedef struct _NMDevicePrivate {
gboolean in_state_changed;
gboolean initialized;
gboolean platform_link_initialized;
@@ -10033,7 +10033,11 @@ _activation_func_to_string (ActivationHandleFunc func)
static void
nm_device_init (NMDevice *self)
{
- NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+ NMDevicePrivate *priv;
+
+ priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DEVICE, NMDevicePrivate);
+
+ self->priv = priv;
priv->type = NM_DEVICE_TYPE_UNKNOWN;
priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;
diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h
index 5d8104b428..45c7306459 100644
--- a/src/devices/nm-device.h
+++ b/src/devices/nm-device.h
@@ -110,8 +110,13 @@ typedef enum { /*< skip >*/
NM_DEVICE_CHECK_CON_AVAILABLE_ALL = (((__NM_DEVICE_CHECK_CON_AVAILABLE_ALL - 1) << 1) - 1),
} NMDeviceCheckConAvailableFlags;
+struct _NMDevicePrivate;
+
struct _NMDevice {
NMExportedObject parent;
+
+ /* private */
+ struct _NMDevicePrivate *priv;
};
/* The flags have an relaxing meaning, that means, specifying more flags, can make