Re: g_list_prepend() does not call g_list_first()



On Thu, 2005-12-01 at 08:36, ANDREW PAPROCKI, BLOOMBERG/ 731 LEXIN
wrote:
> Just wondering if there is a legacy reason why g_list_prepend() does not call 
> g_list_first() on the pointer passed in to ensure that it is prepending to the 
> head of the list. The g_list_append() call ensure it is appending to the end, 
> and this is unintuitive to people. If this seems logical, is this a possible 
> addition to 2.10 since it would change API behavior? Or has this never been done
>  because the impact was deemed to great versus the benefit?

As documented at
http://developer.gnome.org/doc/API/2.0/glib/glib-Doubly-Linked-Lists.html

"Note that most of the GList functions expect to be passed a pointer to
the first element in the list. The functions which insert elements
return the new start of the list, which may have changed."

I'm not aware of anyone who keeps track of a GList by keeping a pointer
to some arbitrary element. Anyone with any sense, in my opinion, keeps a
pointer to the head of the list and uses other pointers when iterating
or referring to some arbitrary element. 

In any case, g_list_prepend() does have a coded (although poorly
documented) behavior in the case of prepending to a middle element. A
quick look at the code reveals that if the list pointer is a middle
element then the new element will be properly placed in the middle of
the list just before the referenced element. All pointers will be
updated so that list integrity is maintained.

I believe that this is a reasonable behavior. But it should be
documented.





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