Re: Glib - more effective code - GNode



"Michal Burda" <michal burda centrum cz> writes:
> Hi
> 
> in file gnode.c, function g_node_first_sibling():
> 
> ...
> while (node->prev)
>   node = node->prev
> return node
> ...
> 
> 
> More effective this:????
> ...
> g_return_val_if_fail(node->parent != NULL, node);
> node = node->parent->children;
> return node;
> ...
> 

Except you need to handle the root node:

 if (node->parent)
   return node->parent->children;
 else
  {
    while (node->prev)
      node = node->prev;
    return node;
  }

Havoc




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