diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index 5c47e44083..92182371cc 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -63,6 +63,8 @@ typedef struct { GMainLoop *loop = NULL; struct termios termios_orig; +NM_CACHED_QUARK_FCN ("nmcli-error-quark", nmcli_error_quark) + static void complete_field (GHashTable *h, const char *setting, NmcOutputField field[]) { @@ -163,18 +165,6 @@ complete_fields (const char *prefix) } -/* Get an error quark for use with GError */ -GQuark -nmcli_error_quark (void) -{ - static GQuark error_quark = 0; - - if (G_UNLIKELY (error_quark == 0)) - error_quark = g_quark_from_static_string ("nmcli-error-quark"); - - return error_quark; -} - static void usage (void) { diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 40322427b4..98899ef7b7 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -2461,13 +2461,12 @@ nm_connection_private_free (NMConnectionPrivate *priv) static NMConnectionPrivate * nm_connection_get_private (NMConnection *connection) { - static GQuark key = 0; + GQuark key; NMConnectionPrivate *priv; nm_assert (NM_IS_CONNECTION (connection)); - if (G_UNLIKELY (key == 0)) - key = g_quark_from_static_string ("NMConnectionPrivate"); + key = NM_CACHED_QUARK ("NMConnectionPrivate"); priv = g_object_get_qdata ((GObject *) connection, key); if (!priv) { diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 82467c9c6a..b9ac5aec97 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -304,8 +304,8 @@ typedef struct { NMSettingPropertyTransformFromFunc from_dbus; } NMSettingProperty; -static GQuark setting_property_overrides_quark; -static GQuark setting_properties_quark; +static NM_CACHED_QUARK_FCN ("nm-setting-property-overrides", setting_property_overrides_quark) +static NM_CACHED_QUARK_FCN ("nm-setting-properties", setting_properties_quark) static NMSettingProperty * find_property (GArray *properties, const char *name) @@ -341,7 +341,7 @@ add_property_override (NMSettingClass *setting_class, GArray *overrides; NMSettingProperty override; - g_return_if_fail (g_type_get_qdata (setting_type, setting_properties_quark) == NULL); + g_return_if_fail (g_type_get_qdata (setting_type, setting_properties_quark ()) == NULL); memset (&override, 0, sizeof (override)); override.name = property_name; @@ -354,10 +354,10 @@ add_property_override (NMSettingClass *setting_class, override.to_dbus = to_dbus; override.from_dbus = from_dbus; - overrides = g_type_get_qdata (setting_type, setting_property_overrides_quark); + overrides = g_type_get_qdata (setting_type, setting_property_overrides_quark ()); if (!overrides) { overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); - g_type_set_qdata (setting_type, setting_property_overrides_quark, overrides); + g_type_set_qdata (setting_type, setting_property_overrides_quark (), overrides); } g_return_if_fail (find_property (overrides, property_name) == NULL); @@ -530,14 +530,14 @@ nm_setting_class_ensure_properties (NMSettingClass *setting_class) GParamSpec **property_specs; guint n_property_specs, i; - properties = g_type_get_qdata (type, setting_properties_quark); + properties = g_type_get_qdata (type, setting_properties_quark ()); if (properties) return properties; /* Build overrides array from @setting_class and its superclasses */ overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); for (otype = type; otype != G_TYPE_OBJECT; otype = g_type_parent (otype)) { - type_overrides = g_type_get_qdata (otype, setting_property_overrides_quark); + type_overrides = g_type_get_qdata (otype, setting_property_overrides_quark ()); if (type_overrides) g_array_append_vals (overrides, (NMSettingProperty *)type_overrides->data, type_overrides->len); } @@ -568,7 +568,7 @@ nm_setting_class_ensure_properties (NMSettingClass *setting_class) } g_array_unref (overrides); - g_type_set_qdata (type, setting_properties_quark, properties); + g_type_set_qdata (type, setting_properties_quark (), properties); return properties; } @@ -1995,11 +1995,6 @@ nm_setting_class_init (NMSettingClass *setting_class) { GObjectClass *object_class = G_OBJECT_CLASS (setting_class); - if (!setting_property_overrides_quark) - setting_property_overrides_quark = g_quark_from_static_string ("nm-setting-property-overrides"); - if (!setting_properties_quark) - setting_properties_quark = g_quark_from_static_string ("nm-setting-properties"); - g_type_class_add_private (setting_class, sizeof (NMSettingPrivate)); /* virtual methods */ diff --git a/libnm/nm-client.c b/libnm/nm-client.c index 63eaa84ce3..cd54a88c70 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -153,15 +153,7 @@ static const GPtrArray empty = { 0, }; * * Returns: the error quark used for #NMClient errors. **/ -GQuark -nm_client_error_quark (void) -{ - static GQuark quark; - - if (G_UNLIKELY (!quark)) - quark = g_quark_from_static_string ("nm-client-error-quark"); - return quark; -} +NM_CACHED_QUARK_FCN ("nm-client-error-quark", nm_client_error_quark) /*****************************************************************************/ diff --git a/src/devices/bluetooth/nm-bt-error.c b/src/devices/bluetooth/nm-bt-error.c index 1839118730..66c65b6d4e 100644 --- a/src/devices/bluetooth/nm-bt-error.c +++ b/src/devices/bluetooth/nm-bt-error.c @@ -22,13 +22,5 @@ #include "nm-bt-error.h" -GQuark -nm_bt_error_quark (void) -{ - static GQuark quark = 0; - if (!quark) - quark = g_quark_from_static_string ("nm-bt-error"); - return quark; -} - +NM_CACHED_QUARK_FCN ("nm-bt-error", nm_bt_error_quark)