# HG changeset patch # User Matti Hamalainen # Date 1188652397 -10800 # Node ID 899a7ed37a70729a74d83b83dcd5ee95496d6131 # Parent 602ec8c40d0dcc92c6c39805a8adbce4d6501772 Clean up tiny bit of code duplication. diff -r 602ec8c40d0d -r 899a7ed37a70 src/audacious/tuple.c --- a/src/audacious/tuple.c Sat Sep 01 07:09:38 2007 +0300 +++ b/src/audacious/tuple.c Sat Sep 01 16:13:17 2007 +0300 @@ -130,24 +130,43 @@ return tuple; } + +static gboolean +tuple_associate_data(const gchar **tfield, TupleValue **value, Tuple *tuple, const gint nfield, const gchar *field) +{ + g_return_val_if_fail(tuple != NULL, FALSE); + g_return_val_if_fail(nfield < FIELD_LAST, FALSE); + + if (nfield < 0) + *tfield = field; + else { + *tfield = tuple_fields[nfield]; + tuple->values[nfield] = NULL; + } + + if ((*value = mowgli_dictionary_delete(tuple->dict, *tfield))) + tuple_disassociate_now(*value); + + return TRUE; +} + +static void +tuple_associate_data2(Tuple *tuple, const gint nfield, const gchar *field, TupleValue *value) +{ + mowgli_dictionary_add(tuple->dict, field, value); + + if (nfield >= 0) + tuple->values[nfield] = value; +} + gboolean tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string) { TupleValue *value; const gchar *tfield; - g_return_val_if_fail(tuple != NULL, FALSE); - g_return_val_if_fail(nfield < FIELD_LAST, FALSE); - - if (nfield < 0) - tfield = field; - else { - tfield = tuple_fields[nfield]; - tuple->values[nfield] = NULL; - } - - if ((value = mowgli_dictionary_delete(tuple->dict, tfield))) - tuple_disassociate_now(value); + if (!tuple_associate_data(&tfield, &value, tuple, nfield, field)) + return FALSE; if (string == NULL) return TRUE; @@ -156,11 +175,7 @@ value->type = TUPLE_STRING; value->value.string = g_strdup(string); - mowgli_dictionary_add(tuple->dict, tfield, value); - - if (nfield >= 0) - tuple->values[nfield] = value; - + tuple_associate_data2(tuple, nfield, tfield, value); return TRUE; } @@ -169,29 +184,15 @@ { TupleValue *value; const gchar *tfield; - - g_return_val_if_fail(tuple != NULL, FALSE); - g_return_val_if_fail(nfield < FIELD_LAST, FALSE); - - if (nfield < 0) - tfield = field; - else { - tfield = tuple_fields[nfield]; - tuple->values[nfield] = NULL; - } - if ((value = mowgli_dictionary_delete(tuple->dict, tfield))) - tuple_disassociate_now(value); + if (!tuple_associate_data(&tfield, &value, tuple, nfield, field)) + return FALSE; value = mowgli_heap_alloc(tuple_value_heap); value->type = TUPLE_INT; value->value.integer = integer; - mowgli_dictionary_add(tuple->dict, tfield, value); - - if (nfield >= 0) - tuple->values[nfield] = value; - + tuple_associate_data2(tuple, nfield, tfield, value); return TRUE; }