Re: g_list_prepend() vs g_list_append()

On Sat, Sep 07, 2002 at 04:20:37PM -0400, Jonathan Blandford wrote:
> Mark Mielke <mark mark mielke cc> writes:
> > I assume that g_list_prepend() and g_list_append() are functions that
> > only function reliably, and intuitively, if they are passed the 'first
> > element in the list', however, their implementations cause me to suspect
> > that either this limitation was not intended, or else, the implementation
> > of g_list_prepend() can be optimized slightly.
> You are always expected to pass the first element of the list into every
> g_list_* function.  Passing an intermediate element isn't expected.
> We could put:
>   if (list != NULL)
>     g_return_val_if_fail (list->prev == NULL, NULL);
> in to catch usage errors like you ran into.

This is actually the 'optimization' that I was considering, although the
size of the function may not be reduced enough to actually result in better
memory cache performance.

I just thought it was worth of being mentioned that they current acted
differently, and that if you (we?) would want to ensure that people do
not unintentionally fall into believing that existing behaviour was proper
and documented behaviour, we should do something like the above.

For my other point, I still wished to see a method of efficiently
appending to a list that does not require g_list_last() to be used for
each append() operation. The cost is linear with the size of the
list. I did not consider using the "list_head" and "list_tail" fields
in GQueue, as any write operations would need to properly update GQueue
in a manner that does not encourage the 'blackbox' approach. Also, GQueue
still looks like a hack at improving GList that might better be implemented
using a circular list...

Just some ideas. I like GLIB, but every time I get around to using it,
I find it to be *so close* to being complete, intuitive, and reliable
(i.e. better than a majority of other attempts made), but with a few
inconsistencies and partial implementations that leave me hanging... :-)

Yes, I know I come across as a perfectionist.


mark mielke cc/markm ncf ca/markm nortelnetworks com __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | 
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...


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