Changeset fc8a87a


Ignore:
Timestamp:
Jun 25, 2011, 3:26:15 AM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
f9df2f0
Parents:
12294d2
git-author:
David Benjamin <davidben@mit.edu> (03/10/11 14:49:02)
git-committer:
David Benjamin <davidben@mit.edu> (06/25/11 03:26:15)
Message:
Replace owl_messagelist's internal owl_list with GPtrArray
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • messagelist.c

    rd427f08 rfc8a87a  
    33#include <string.h>
    44
    5 int owl_messagelist_create(owl_messagelist *ml)
     5void owl_messagelist_create(owl_messagelist *ml)
    66{
    7   owl_list_create(&(ml->list));
    8   return(0);
     7  ml->list = g_ptr_array_new();
     8}
     9
     10void owl_messagelist_cleanup(owl_messagelist *ml, bool free_messages)
     11{
     12  if (free_messages)
     13    g_ptr_array_foreach(ml->list, (GFunc)owl_message_delete, NULL);
     14  g_ptr_array_free(ml->list, true);
    915}
    1016
    1117int owl_messagelist_get_size(const owl_messagelist *ml)
    1218{
    13   return(owl_list_get_size(&(ml->list)));
     19  return ml->list->len;
    1420}
    1521
    1622void *owl_messagelist_get_element(const owl_messagelist *ml, int n)
    1723{
    18   return(owl_list_get_element(&(ml->list), n));
     24  return ml->list->pdata[n];
    1925}
    2026
     
    2632
    2733  first = 0;
    28   last = owl_list_get_size(&(ml->list)) - 1;
     34  last = ml->list->len - 1;
    2935  while (first <= last) {
    3036    mid = (first + last) / 2;
    31     m = owl_list_get_element(&(ml->list), mid);
     37    m = ml->list->pdata[mid];
    3238    msg_id = owl_message_get_id(m);
    3339    if (msg_id == target_id) {
     
    4450void owl_messagelist_append_element(owl_messagelist *ml, void *element)
    4551{
    46   owl_list_append_element(&ml->list, element);
     52  g_ptr_array_add(ml->list, element);
    4753}
    4854
     
    5157{
    5258  /* mark a message as deleted */
    53   owl_message_mark_delete(owl_list_get_element(&(ml->list), n));
     59  owl_message_mark_delete(ml->list->pdata[n]);
    5460  return(0);
    5561}
     
    5864{
    5965  /* mark a message as deleted */
    60   owl_message_unmark_delete(owl_list_get_element(&(ml->list), n));
     66  owl_message_unmark_delete(ml->list->pdata[n]);
    6167  return(0);
    6268}
     
    6571{
    6672  /* expunge deleted messages */
    67   int i, j;
    68   owl_list newlist;
     73  int i;
     74  GPtrArray *newlist;
    6975  owl_message *m;
    7076
    71   owl_list_create(&newlist);
     77  newlist = g_ptr_array_new();
    7278  /*create a new list without messages marked as deleted */
    73   j=owl_list_get_size(&(ml->list));
    74   for (i=0; i<j; i++) {
    75     m=owl_list_get_element(&(ml->list), i);
     79  for (i = 0; i < ml->list->len; i++) {
     80    m = ml->list->pdata[i];
    7681    if (owl_message_is_delete(m)) {
    7782      owl_message_delete(m);
    7883    } else {
    79       owl_list_append_element(&newlist, m);
     84      g_ptr_array_add(newlist, m);
    8085    }
    8186  }
    8287
    8388  /* free the old list */
    84   owl_list_cleanup(&(ml->list), NULL);
     89  g_ptr_array_free(ml->list, true);
    8590
    8691  /* copy the new list to the old list */
     
    9297void owl_messagelist_invalidate_formats(const owl_messagelist *ml)
    9398{
    94   int i, j;
     99  int i;
    95100  owl_message *m;
    96101
    97   j=owl_list_get_size(&(ml->list));
    98   for (i=0; i<j; i++) {
    99     m=owl_list_get_element(&(ml->list), i);
     102  for (i = 0; i < ml->list->len; i++) {
     103    m = ml->list->pdata[i];
    100104    owl_message_invalidate_format(m);
    101105  }
  • owl.h

    r12294d2 rfc8a87a  
    422422
    423423typedef struct _owl_messagelist {
    424   owl_list list;
     424  GPtrArray *list;
    425425} owl_messagelist;
    426426
  • view.c

    r3b8a563 rfc8a87a  
    3737  ml=&(v->ml);
    3838
    39   /* nuke the old list */
    40   owl_list_cleanup(&ml->list, NULL);
     39  /* nuke the old list, don't free the messages */
     40  owl_messagelist_cleanup(ml, false);
    4141  owl_messagelist_create(&(v->ml));
    4242
     
    159159void owl_view_cleanup(owl_view *v)
    160160{
    161   owl_list_cleanup(&v->ml.list, NULL);
     161  owl_messagelist_cleanup(&v->ml, false);
    162162  g_free(v->name);
    163163}
Note: See TracChangeset for help on using the changeset viewer.