Changeset 399

Show
Ignore:
Timestamp:
05/27/06 12:43:53
Author:
pvanhoof
Message:

Speed hack

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymailui-gtk/tny-msg-header-list-model.c

    r380 r399  
    3939        gint length; 
    4040        gint stamp; 
     41 
     42        guint last_nth; 
     43        GList *last_iter; 
    4144}; 
    4245 
     
    9396} 
    9497 
     98static GList* 
     99g_list_travel_to_nth (GList *list, guint cur, guint nth) 
     100{ 
     101        if (cur == nth) 
     102                return list; 
     103 
     104        if (cur < nth) 
     105                while ((cur++ < nth) && list) 
     106                        list = list->next; 
     107        else if (cur > nth) 
     108                while ((cur-- > nth) && list) 
     109                        list = list->prev; 
     110 
     111        return list; 
     112} 
     113 
    95114static gboolean 
    96115tny_msg_header_list_model_get_iter (GtkTreeModel *self, GtkTreeIter *iter, GtkTreePath *path) 
     
    103122 
    104123        g_mutex_lock (list_model->folder_lock); 
    105  
    106         headers = (GList*)tny_msg_folder_iface_get_headers (list_model->folder, FALSE); 
    107124         
    108125        i = gtk_tree_path_get_indices (path)[0]; 
    109         list = g_list_nth (G_LIST (headers), i); 
     126 
     127 
     128        if (list_model->last_iter) 
     129        { /* This is a little speed hack */ 
     130                list_model->last_iter = g_list_travel_to_nth (list_model->last_iter, list_model->last_nth, i); 
     131                list_model->last_nth = i; 
     132                list = list_model->last_iter; 
     133        } else { 
     134                headers = (GList*)tny_msg_folder_iface_get_headers (list_model->folder, FALSE); 
     135                list_model->last_nth = i; 
     136                list = g_list_nth (G_LIST (headers), i); 
     137                list_model->last_iter = list; 
     138        } 
     139 
    110140 
    111141        if (G_UNLIKELY (i >= list_model->length)) 
     
    359389{ 
    360390        self->length = 0; 
     391        self->last_iter = NULL; 
     392        self->last_nth = 0; 
    361393 
    362394        return; 
     
    386418 
    387419        /* We have to unreference all */ 
    388         if (self->folder) { 
     420        if (self->folder)  
     421        { 
    389422                headers = tny_msg_folder_iface_get_headers (self->folder, FALSE); 
    390423                g_list_foreach ((GList*)headers, unref_header, NULL); 
     
    420453        self->folder = NULL; 
    421454        self->folder_lock = g_mutex_new (); 
     455        destroy_internal_list (self); 
    422456 
    423457        return; 
     
    443477        g_mutex_lock (self->folder_lock); 
    444478 
     479        destroy_internal_list (self); 
     480 
    445481        headers = tny_msg_folder_iface_get_headers (folder, refresh); 
    446482 
     
    479515 
    480516        model = g_object_new (TNY_TYPE_MSG_HEADER_LIST_MODEL, NULL); 
    481          
     517 
    482518        return GTK_TREE_MODEL (model); 
    483519}