Speed improvement of g_list_append
- From: Emmanuel <e allaud wanadoo fr>
- To: balsa-list gnome org
- Subject: Speed improvement of g_list_append
- Date: Wed, 20 Jun 2001 08:01:43 +0200
Hi,
Still on the g_list_append thing :)
We could just keep track of the current last element and append after
it, in this case, because current_last->next==NULL, g_list_append() will
just update current_last->next and won't traverse all the list. Here is
the code
list = g_list_sort(list, (GCompareFunc)address_compare);
addr_vcard->address_list = list;
completion_list = NULL;
if (list) { // if the list is non-empty
// we construct the first element
current_last=completion_list =
g_list_append(NULL,completion_data_new(LIBBALSA_ADDRESS(list->data),
FALSE));
while ( list->next ) { // if there is one
more element in list
list = g_list_next(list); // we select if
cmp_data = completion_data_new(LIBBALSA_ADDRESS(list->data),
FALSE);
// we append to completion_list but giving current_last, we just make
the append directly at the last element of the list
// and we update current_last to point on the last element of the
completion_list
current_last=g_list_next(g_list_append(current_last,cmp_data));
}
}
g_completion_add_items(addr_vcard->name_complete, completion_list);
// no more reverse_list
g_list_free(completion_list);
Yes I know it's a bit more complicated, and moreover I haven't a clue if
the speed gain is worth it :)
One more thing, in fact g_list_append(list,new_element) will allways
append to the end of the list (ie it will look for the end of "list" to
do the append), whereas g_list_prepend(list,new_element) just puts
"new_element" before "list" (it won't search the actual beginning of
list).
Thnaks if you've read until here :)
Manu
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]