GSettings: peek instead of ref/unref enum class

We only ever do the enum mapping for the property binding in the case
that a GParamSpecEnum exists and in that case the class is already
referenced by the GParamSpec.  Use peek instead of ref/unref and add a
clarifying note.
This commit is contained in:
Ryan Lortie 2010-06-28 13:58:25 -04:00
parent 168cfc5922
commit ab1111b8bb

View File

@ -382,9 +382,9 @@ g_settings_set_mapping (const GValue *value,
GEnumValue *enumval; GEnumValue *enumval;
GEnumClass *eclass; GEnumClass *eclass;
eclass = g_type_class_ref (G_VALUE_TYPE (value)); /* GParamSpecEnum holds a ref on the class so we just peek... */
eclass = g_type_class_peek (G_VALUE_TYPE (value));
enumval = g_enum_get_value (eclass, g_value_get_enum (value)); enumval = g_enum_get_value (eclass, g_value_get_enum (value));
g_type_class_unref (eclass);
if (enumval) if (enumval)
return g_variant_new_string (enumval->value_nick); return g_variant_new_string (enumval->value_nick);
@ -454,10 +454,10 @@ g_settings_get_mapping (GValue *value,
GEnumValue *evalue; GEnumValue *evalue;
const gchar *nick; const gchar *nick;
eclass = g_type_class_ref (G_VALUE_TYPE (value)); /* GParamSpecEnum holds a ref on the class so we just peek... */
eclass = g_type_class_peek (G_VALUE_TYPE (value));
nick = g_variant_get_string (variant, NULL); nick = g_variant_get_string (variant, NULL);
evalue = g_enum_get_value_by_nick (eclass, nick); evalue = g_enum_get_value_by_nick (eclass, nick);
g_type_class_unref (eclass);
if (evalue) if (evalue)
{ {