all: use NM_CACHED_QUARK_FCN() to define cached quarks

This commit is contained in:
Thomas Haller 2017-02-03 17:21:21 +01:00
parent 7d6b8bab70
commit dc40288849
5 changed files with 14 additions and 46 deletions

View file

@ -63,6 +63,8 @@ typedef struct {
GMainLoop *loop = NULL; GMainLoop *loop = NULL;
struct termios termios_orig; struct termios termios_orig;
NM_CACHED_QUARK_FCN ("nmcli-error-quark", nmcli_error_quark)
static void static void
complete_field (GHashTable *h, const char *setting, NmcOutputField field[]) 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 static void
usage (void) usage (void)
{ {

View file

@ -2461,13 +2461,12 @@ nm_connection_private_free (NMConnectionPrivate *priv)
static NMConnectionPrivate * static NMConnectionPrivate *
nm_connection_get_private (NMConnection *connection) nm_connection_get_private (NMConnection *connection)
{ {
static GQuark key = 0; GQuark key;
NMConnectionPrivate *priv; NMConnectionPrivate *priv;
nm_assert (NM_IS_CONNECTION (connection)); nm_assert (NM_IS_CONNECTION (connection));
if (G_UNLIKELY (key == 0)) key = NM_CACHED_QUARK ("NMConnectionPrivate");
key = g_quark_from_static_string ("NMConnectionPrivate");
priv = g_object_get_qdata ((GObject *) connection, key); priv = g_object_get_qdata ((GObject *) connection, key);
if (!priv) { if (!priv) {

View file

@ -304,8 +304,8 @@ typedef struct {
NMSettingPropertyTransformFromFunc from_dbus; NMSettingPropertyTransformFromFunc from_dbus;
} NMSettingProperty; } NMSettingProperty;
static GQuark setting_property_overrides_quark; static NM_CACHED_QUARK_FCN ("nm-setting-property-overrides", setting_property_overrides_quark)
static GQuark setting_properties_quark; static NM_CACHED_QUARK_FCN ("nm-setting-properties", setting_properties_quark)
static NMSettingProperty * static NMSettingProperty *
find_property (GArray *properties, const char *name) find_property (GArray *properties, const char *name)
@ -341,7 +341,7 @@ add_property_override (NMSettingClass *setting_class,
GArray *overrides; GArray *overrides;
NMSettingProperty override; 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)); memset (&override, 0, sizeof (override));
override.name = property_name; override.name = property_name;
@ -354,10 +354,10 @@ add_property_override (NMSettingClass *setting_class,
override.to_dbus = to_dbus; override.to_dbus = to_dbus;
override.from_dbus = from_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) { if (!overrides) {
overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); 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); 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; GParamSpec **property_specs;
guint n_property_specs, i; 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) if (properties)
return properties; return properties;
/* Build overrides array from @setting_class and its superclasses */ /* Build overrides array from @setting_class and its superclasses */
overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty)); overrides = g_array_new (FALSE, FALSE, sizeof (NMSettingProperty));
for (otype = type; otype != G_TYPE_OBJECT; otype = g_type_parent (otype)) { 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) if (type_overrides)
g_array_append_vals (overrides, (NMSettingProperty *)type_overrides->data, type_overrides->len); 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_array_unref (overrides);
g_type_set_qdata (type, setting_properties_quark, properties); g_type_set_qdata (type, setting_properties_quark (), properties);
return properties; return properties;
} }
@ -1995,11 +1995,6 @@ nm_setting_class_init (NMSettingClass *setting_class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (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)); g_type_class_add_private (setting_class, sizeof (NMSettingPrivate));
/* virtual methods */ /* virtual methods */

View file

@ -153,15 +153,7 @@ static const GPtrArray empty = { 0, };
* *
* Returns: the error quark used for #NMClient errors. * Returns: the error quark used for #NMClient errors.
**/ **/
GQuark NM_CACHED_QUARK_FCN ("nm-client-error-quark", nm_client_error_quark)
nm_client_error_quark (void)
{
static GQuark quark;
if (G_UNLIKELY (!quark))
quark = g_quark_from_static_string ("nm-client-error-quark");
return quark;
}
/*****************************************************************************/ /*****************************************************************************/

View file

@ -22,13 +22,5 @@
#include "nm-bt-error.h" #include "nm-bt-error.h"
GQuark NM_CACHED_QUARK_FCN ("nm-bt-error", nm_bt_error_quark)
nm_bt_error_quark (void)
{
static GQuark quark = 0;
if (!quark)
quark = g_quark_from_static_string ("nm-bt-error");
return quark;
}