Re: Followup: GtkTree update



On Mon, 2 Oct 2000 jrb redhat com wrote:

> Havoc just yelled at me for not Posting headers.  Here they are for your
> commenting pleasure.

Ok, just did a quick read of this. Here are some comments.
 
> struct _GtkTreeModelClass
> {
>   GtkObjectClass parent_class;
> 
 ...
>   gboolean     (* node_next)       (GtkTreeModel *tree_model,
> 				    GtkTreeNode  *node);
>   GtkTreeNode  (* node_children)   (GtkTreeModel *tree_model,
> 				    GtkTreeNode   node);
>   gboolean     (* node_has_child)  (GtkTreeModel *tree_model,
> 				    GtkTreeNode   node);
>   gint         (* node_n_children) (GtkTreeModel *tree_model,
> 				    GtkTreeNode   node);
>   GtkTreeNode  (* node_nth_child)  (GtkTreeModel *tree_model,
> 				    GtkTreeNode   node,
>   GtkTreeNode  (* node_parent)     (GtkTreeModel *tree_model,
> 				     gint          n);

These kinds of interfaces (node_nth_child) are dangerous. I've fixed a
few misuses of things like it in mozilla. The problem is that the
interface makes it look like a O(1) operation to get the nth child. This
can lead to (it did in the mozilla code) users coding stuff like:

n = node_n_children()
for (i=0; i < n; i++) {
  node = node_nth_child(i);
  do_some_stuff(node);
}

Since the implementation of the children often are lists, this loop has
O(n^2) behaviour. Now, the correct way to do this loop would be to use
node_children and node_next, but that is not obvious from the interface.

Is there any specific reason you added the node_nth_child call?

> /* Only meaningful if GTK_TREE_SELECTION_SINGLE is set */
> /* User selected_foreach for GTK_TREE_SELECTION_MULTI */

     ^^^^ I suppose you mean "Use"

/ Alex






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