GList changes




These functions simplify the 3 cases of insert to 2, and 
allow the user to not need to deal with head and iter at
the same time.

New functions 
  g_list_insert_link(GList *head,gpointer data,GList* iter); 
  g_list_insert_after_link(GList *head,gpointer data,GList* iter); 

The other functions are converted to use these.
 
--Karl

Index: glib.h
===================================================================
RCS file: /cvs/gnome/glib/glib.h,v
retrieving revision 1.135
diff -r1.135 glib.h
882a883,888
> GList* g_list_insert_link       (GList          *list,
>                                  gpointer        data,
>                                  GList          *llink);
> GList* g_list_insert_after_link (GList          *list,
>                                  gpointer        data,
>                                  GList          *llink);
Index: glist.c
===================================================================
RCS file: /cvs/gnome/glib/glist.c,v
retrieving revision 1.13
diff -r1.13 glist.c
173,189c173
<   GList *new_list;
<   GList *last;
<   
<   new_list = g_list_alloc ();
<   new_list->data = data;
<   
<   if (list)
<     {
<       last = g_list_last (list);
<       /* g_assert (last != NULL); */
<       last->next = new_list;
<       new_list->prev = last;
< 
<       return list;
<     }
<   else
<     return new_list;
---
>   return g_list_insert_after_link(list,data,0);
195a180,198
>   return g_list_insert_link(list,data,list);
> }
> 
> GList*
> g_list_insert (GList  *list,
>              gpointer  data,
>              gint      position)
> {
>   if (position < 0)
>     return g_list_insert_link(list,data,0);
> 
>   return g_list_insert_link(list,data,g_list_nth (list, position));
> }
> 
> GList*
> g_list_insert_link (GList     *list,
>                   gpointer    data,
>                   GList       *link)
> {
197c200
<   
---
> 
200,201c203,211
<   
<   if (list)
---
> 
>   if (!list)
>     return new_list; 
> 
>   if (!link) 
>     link=g_list_last(list);
> 
>   new_list->next = link;
>   if (link->prev)
203,209c213,214
<       if (list->prev)
<       {
<         list->prev->next = new_list;
<         new_list->prev = list->prev;
<       }
<       list->prev = new_list;
<       new_list->next = list;
---
>       link->prev->next = new_list;
>       new_list->prev = link->prev;
211,212c216,221
<   
<   return new_list;
---
>   link->prev = new_list;
> 
>   if (link == list)
>     return new_list;
> 
>   return list;
216,218c225,227
< g_list_insert (GList  *list,
<              gpointer  data,
<              gint      position)
---
> g_list_insert_after_link (GList       *list,
>                   gpointer    data,
>                   GList       *link)
221,231c230
<   GList *tmp_list;
<   
<   if (position < 0)
<     return g_list_append (list, data);
<   else if (position == 0)
<     return g_list_prepend (list, data);
<   
<   tmp_list = g_list_nth (list, position);
<   if (!tmp_list)
<     return g_list_append (list, data);
<   
---
> 
234,235c233,241
<   
<   if (tmp_list->prev)
---
> 
>   if (!list)
>     return new_list; 
> 
>   if (!link) 
>     link=g_list_last(list);
> 
>   new_list->prev = link;
>   if (link->next)
237,238c243,244
<       tmp_list->prev->next = new_list;
<       new_list->prev = tmp_list->prev;
---
>       link->next->prev = new_list;
>       new_list->next = link->next;
240,246c246,248
<   new_list->next = tmp_list;
<   tmp_list->prev = new_list;
<   
<   if (tmp_list == list)
<     return new_list;
<   else
<     return list;
---
>   link->next = new_list;
> 
>   return list;
247a250
> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]