diff src/audacious/tuple.c @ 3409:86dafe2300f7 trunk

Added Tuplez compiler (not used yet, though) and some related changes in tuple code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 30 Aug 2007 23:41:33 +0300
parents 70149c3555f4
children 7c2e63c5a001 9580bb3e58fa
line wrap: on
line diff
--- a/src/audacious/tuple.c	Thu Aug 30 17:41:40 2007 +0200
+++ b/src/audacious/tuple.c	Thu Aug 30 23:41:33 2007 +0300
@@ -23,19 +23,6 @@
 
 #include "tuple.h"
 
-struct _Tuple {
-    mowgli_object_t parent;
-    mowgli_dictionary_t *dict;
-};
-
-typedef struct {
-    TupleValueType type;
-    union {
-        gchar *string;
-        gint integer;
-    } value;
-} TupleValue;
-
 static mowgli_heap_t *tuple_heap = NULL;
 static mowgli_heap_t *tuple_value_heap = NULL;
 static mowgli_object_class_t tuple_klass;
@@ -124,8 +111,8 @@
     g_return_val_if_fail(tuple != NULL, FALSE);
     g_return_val_if_fail(field != NULL, FALSE);
 
-    if (mowgli_dictionary_find(tuple->dict, field))
-        tuple_disassociate(tuple, field);
+    if ((value = mowgli_dictionary_delete(tuple->dict, field)))
+        tuple_disassociate_now(value);
 
     if (string == NULL)
         return TRUE;
@@ -147,8 +134,8 @@
     g_return_val_if_fail(tuple != NULL, FALSE);
     g_return_val_if_fail(field != NULL, FALSE);
 
-    if (mowgli_dictionary_find(tuple->dict, field))
-        tuple_disassociate(tuple, field);
+    if ((value = mowgli_dictionary_delete(tuple->dict, field)))
+        tuple_disassociate_now(value);
 
     value = mowgli_heap_alloc(tuple_value_heap);
     value->type = TUPLE_INT;
@@ -160,6 +147,15 @@
 }
 
 void
+tuple_disassociate_now(TupleValue *value)
+{
+    if (value->type == TUPLE_STRING)
+        g_free(value->value.string);
+
+    mowgli_heap_free(tuple_value_heap, value);
+}
+
+void
 tuple_disassociate(Tuple *tuple, const gchar *field)
 {
     TupleValue *value;
@@ -170,11 +166,8 @@
     /* why _delete()? because _delete() returns the dictnode's data on success */
     if ((value = mowgli_dictionary_delete(tuple->dict, field)) == NULL)
         return;
-
-    if (value->type == TUPLE_STRING)
-        g_free(value->value.string);
-
-    mowgli_heap_free(tuple_value_heap, value);
+    
+    tuple_disassociate_now(value);
 }
 
 TupleValueType