mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 19:00:16 +01:00
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
This commit is contained in:
parent
2077dee582
commit
04c70c76bc
2 changed files with 12 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue