Re: simple performance question



>  I have seen, that the g_list_append in glib function always searches the
>  end of the list, since there is no pointer to the last element. And I have
>  seen, that a few programs uses this function to set up lists.

Most lists are short and then do not need any further optimization.
Places in Gtk and and Gnome where there could be potentially very long
lists use the following method:

      struct SomeGtkObject {
	     ...
	     GList *items_list;
	     GList *items_list_end;
      };

And to insert an item at the end of the list, you can use the
following code:

	  if (!items_list) {
	     items_list = g_list_append (items_list, my_data);
	     items_list_end = items_list;
	  } else
	     items_list_end = g_list_append (items_list_end, my_data)->next;

So it's not hard to do.  If you will be having very long lists, you
may want to consider using this method.

  Federico



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