[Gegl-developer] BABL list API patch

2008-04-01 Thread Jan Heller
Hi,
 attached is a patch that introduces minimal changes needed
 for removal of the old list routines. It ports several
 lists to the new API and deletes the unused old functions.

 There are still several plain C arrays in the code used as lists, 
 however, these do not depend on the old routines and are
 left untouched by the patch. I can try to identify and port these as
 well. This would certainly improve things from the
 readability point of view, although it wouldn't IMO do much
 about the speed of the code.

 To Sven: Thanks for including me into the AUTHORS file :)

 Regards,
   Jan
Index: babl/babl-model.c
===
--- babl/babl-model.c   (revision 299)
+++ babl/babl-model.c   (working copy)
@@ -27,7 +27,8 @@ static int
 each_babl_model_destroy (Babl *babl,
  void *data)
 {
-  babl_free (babl-model.from);
+  if (babl-model.from_list)
+babl_list_destroy (babl-model.from_list);
   babl_free (babl);
   return 0;  /* continue iterating */
 }
@@ -72,7 +73,7 @@ model_new (const char *name,
   strcpy (babl-instance.name, name);
   memcpy (babl-model.component, component, sizeof (BablComponent *) * 
components);
 
-  babl-model.from = NULL;
+  babl-model.from_list  = NULL;
   return babl;
 }
 
Index: babl/babl-sampling.c
===
--- babl/babl-sampling.c(revision 299)
+++ babl/babl-sampling.c(working copy)
@@ -46,7 +46,8 @@ static int
 each_babl_sampling_destroy (Babl *babl,
 void *data)
 {
-  babl_free (babl-sampling.from);
+  if (babl-sampling.from_list)
+babl_list_destroy (babl-sampling.from_list);
   return 0;  /* continue iterating */
 }
 
Index: babl/babl-list.c
===
--- babl/babl-list.c(revision 299)
+++ babl/babl-list.c(working copy)
@@ -16,11 +16,8 @@
  * http://www.gnu.org/licenses/.
  */
 
-/* Implementation of list data structure. This is a bit superior
- * to the list implementation in babl-util.c.
+/* Implementation of list data structure. 
  * Copyright (C) 2008, Jan Heller
- *
- * TODO: migrate babl to BablList
  */
 
 #include babl-internal.h
@@ -30,11 +27,19 @@
 BablList *
 babl_list_init (void)
 {
+  return babl_list_init_with_size (BABL_LIST_INITIAL_SIZE);
+}
+
+BablList *
+babl_list_init_with_size (int initial_size)
+{
   BablList *list = babl_calloc (sizeof (BablList), 1);
 
   babl_assert (list);
 
-  list-size = BABL_LIST_INITIAL_SIZE;
+  if (initial_size == 0)
+initial_size = 1;
+  list-size = initial_size;
   list-count = 0;
   list-items = NULL;
   if (list-size) 
@@ -81,13 +86,10 @@ babl_list_insert (BablList *list,
 list-items[list-count++] = item;
 }
 
-/* TODO: Rename babl_list_each_temp to babl_list_each after the list migration
- */
-
 void
-babl_list_each_temp (BablList *list,
- BablEachFunction each_fun,
- void *user_data)
+babl_list_each (BablList *list,
+BablEachFunction each_fun,
+void *user_data)
 {
   int i;
 
Index: babl/babl-list.h
===
--- babl/babl-list.h(revision 299)
+++ babl/babl-list.h(working copy)
@@ -20,12 +20,13 @@
 #define _BABL_LIST_H
 
 #ifndef _BABL_CLASSES_H
+/* babl-classes.h contains forward declaration
+ * typedef struct _BablList BablList;
+ */
 #error  babl-list.h is only to be included after babl-classes.h
 #endif
 
 
-typedef struct _BablList BablList;
-
 typedef struct _BablList
 {
   int  count;
@@ -37,6 +38,9 @@ typedef struct _BablList
 BablList *
 babl_list_init (void);
 
+BablList *
+babl_list_init_with_size (int initial_size);
+
 void
 babl_list_destroy (BablList *list);
 
@@ -48,9 +52,9 @@ babl_list_insert (BablList *list,
   Babl *item);
 
 void
-babl_list_each_temp (BablList  *list,
- BablEachFunction each_fun,
- void *user_data);
+babl_list_each (BablList  *list,
+BablEachFunction each_fun,
+void *user_data);
 
 
 #endif
Index: babl/babl-internal.h
===
--- babl/babl-internal.h(revision 299)
+++ babl/babl-internal.h(working copy)
@@ -25,6 +25,7 @@
 
 #define BABL_MAX_COMPONENTS   32
 #define BABL_HARD_MAX_PATH_LENGTH  8
+#define BABL_CONVERSIONS   5
 
 #include stdlib.h
 #include stdio.h
Index: babl/babl-fish-path.c
===
--- babl/babl-fish-path.c   (revision 299)
+++ babl/babl-fish-path.c   (working copy)
@@ -141,10 +141,10 @@ get_conversion_chain (const Babl  *f
   temp_chain[temp_conversions] = NULL;
   babl_assert (from);
   babl_assert (from-class_type == BABL_FORMAT);
-  if 

Re: [Gegl-developer] BABL list API patch

2008-04-01 Thread Øyvind Kolås
On Tue, Apr 1, 2008 at 8:13 PM, Jan Heller [EMAIL PROTECTED] wrote:
   attached is a patch that introduces minimal changes needed
   for removal of the old list routines. It ports several
   lists to the new API and deletes the unused old functions.

The patch has been applied.

   There are still several plain C arrays in the code used as lists,
   however, these do not depend on the old routines and are
   left untouched by the patch. I can try to identify and port these as
   well. This would certainly improve things from the
   readability point of view, although it wouldn't IMO do much
   about the speed of the code.

Improving the readability in babl is probably important the code hasn't been
properly handled in years, and it contains half implemented and thus
unused features. Someone cleaning up and perhaps thinking about how to
make babl do more of what it could be doing is very welcome.

/Øyvind K.
-- 
«The future is already here. It's just not very evenly distributed»
 -- William Gibson
http://pippin.gimp.org/ http://ffii.org/
___
Gegl-developer mailing list
Gegl-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gegl-developer