Re: gtk_ctree_insert_node - why so slow?



Olaf Frączyk wrote:

On 2001.11.15 13:50:54 +0100 John Cupitt wrote:

Hi Olaf, could you post a test program that shows this bad behaviour? It'll save us each making one :-)

(maybe you have auto_sort turned on? turn it off, insert 6000 times, then turn it on again)

As you wish, I attache a 2 sample programs:
one adds with siblings, other without.

Hi again, I did some poking about, and I think gtk_ctree_insert_node() is just slow if you are appending. Even if sibling is non-NULL, it still does a lengthy search in gtk_ctree_link().

I don't understand why this is -- the row list is doubly linked, it shouldn't need to search. I think the only solution is to build your node list backwards (always pass the first child in as the sibling).

Here's a version of your program which tries to append quickly (and fails)

--
#include <stdio.h>
#include <gtk/gtk.h>

static void
fill_tree( GtkCTree *ctree, int num_of_rows )
{
	int i;
	GtkCTreeNode *node, *last_node;
	gchar *text[2];
	char buf[255];

	gtk_clist_freeze( GTK_CLIST( ctree ) );

	sprintf( buf, "last node" );
	text[0] = buf;
	text[1] = NULL;
	last_node = gtk_ctree_insert_node( ctree,
		NULL, NULL, text, 2, NULL, NULL, NULL, NULL, TRUE,
		TRUE );

	for( node = NULL, i = 0; i < num_of_rows; i++ ) {
		sprintf( buf, "node %i in tree", i );
		text[0] = buf;
		text[1] = NULL;

		node = gtk_ctree_insert_node( ctree,
			NULL, last_node, text, 2, NULL, NULL, NULL, NULL, TRUE,
			TRUE );
	}

	gtk_ctree_remove_node( ctree, last_node );

	gtk_clist_thaw( GTK_CLIST( ctree ) );
}


int
main( int argc, char *argv[] )
{
	GTimer *timer = g_timer_new();

	GtkWidget *window;
	GtkWidget *ctree;
	GtkWidget *swin;

	gtk_init( &argc, &argv );

	window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
	swin = gtk_scrolled_window_new( NULL, NULL );
	gtk_container_add( GTK_CONTAINER( window ), swin );	
	ctree = gtk_ctree_new( 1, 0 );
	gtk_container_add( GTK_CONTAINER( swin ), ctree );	

	g_timer_reset( timer );
	fill_tree( GTK_CTREE( ctree ), 6000 );
	printf( "Tree fill took %.3fs\n", g_timer_elapsed( timer, NULL ) );

	gtk_widget_show_all( window );

	gtk_main();

	return( 0 );	
}
--




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