diff options
author | Thomas Haller <thaller@redhat.com> | 2016-04-22 19:14:07 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-28 14:58:17 +0200 |
commit | d350d72a2ec2a32423b71d24dd2885efb05724af (patch) | |
tree | 91fa6b5028ad4518ee7f76e106c2d0bc0998e911 | |
parent | 8bc895d5aa27e70a4302598d6a7c39b786acf4a0 (diff) | |
download | NetworkManager-d350d72a2ec2a32423b71d24dd2885efb05724af.tar.gz |
libnm: store NMConnectionPrivate via g_object_set_qdata()
g_object_get_data() and g_object_get_qdata() end up to be identical,
except that g_object_get_data() also requires to intern the string
on every lookup (which involves a hash lookup and locking).
-rw-r--r-- | libnm-core/nm-connection.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index d95e11583a..b2c4d4eea0 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -2253,13 +2253,19 @@ nm_connection_private_free (NMConnectionPrivate *priv) static NMConnectionPrivate * nm_connection_get_private (NMConnection *connection) { + static GQuark key = 0; NMConnectionPrivate *priv; - priv = g_object_get_data (G_OBJECT (connection), "NMConnectionPrivate"); + nm_assert (NM_IS_CONNECTION (connection)); + + if (G_UNLIKELY (key == 0)) + key = g_quark_from_static_string ("NMConnectionPrivate"); + + priv = g_object_get_qdata ((GObject *) connection, key); if (!priv) { priv = g_slice_new0 (NMConnectionPrivate); - g_object_set_data_full (G_OBJECT (connection), "NMConnectionPrivate", - priv, (GDestroyNotify) nm_connection_private_free); + g_object_set_qdata_full ((GObject *) connection, key, + priv, (GDestroyNotify) nm_connection_private_free); priv->self = connection; priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); |