Hi, I recently spent a fun afternoon trying to work out why dlist->tail didn't do what I expected it to (I'm not very bright). After working out that tailpred (tail predecessor) was what I wanted and that tail was never used, I couldn't see any reason for the fields to be named according to their use. So here it is. Matthew W.S. Bell From: Matthew W. S. Bell <matthew bells23 org uk> --- camel/camel-block-file.c | 2 +- camel/camel-iconv.c | 22 +++++++++++----------- camel/camel-list-utils.c | 20 ++++++++++---------- camel/camel-list-utils.h | 8 ++++---- camel/camel-text-index.c | 2 +- libedataserver/e-iconv.c | 22 +++++++++++----------- libedataserver/e-msgport.c | 22 +++++++++++----------- libedataserver/e-msgport.h | 4 ++-- 8 files changed, 51 insertions(+), 51 deletions(-) diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c index 673ff80..06d1361 100644 --- a/camel/camel-block-file.c +++ b/camel/camel-block-file.c @@ -574,7 +574,7 @@ CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id) g_hash_table_insert(bs->blocks, GUINT_TO_POINTER(bl->id), bl); /* flush old blocks */ - flush = (CamelBlock *)bs->block_cache.tailpred; + flush = (CamelBlock *)bs->block_cache.tail; prev = flush->prev; while (bs->block_cache_count > bs->block_cache_limit && prev) { if (flush->refcount == 0) { diff --git a/camel/camel-iconv.c b/camel/camel-iconv.c index 2533d1f..78c87a6 100644 --- a/camel/camel-iconv.c +++ b/camel/camel-iconv.c @@ -60,11 +60,11 @@ typedef struct _CamelDListNode { typedef struct _CamelDList { struct _CamelDListNode *head; + struct _CamelDListNode *terminator; struct _CamelDListNode *tail; - struct _CamelDListNode *tailpred; } CamelDList; -#define CAMEL_DLIST_INITIALISER(l) { (CamelDListNode *)&l.tail, 0, (CamelDListNode *)&l.head } +#define CAMEL_DLIST_INITIALISER(l) { (CamelDListNode *)&l.terminator, 0, (CamelDListNode *)&l.head } struct _iconv_cache_node { struct _iconv_cache_node *next; @@ -160,9 +160,9 @@ struct { and g_list's are f@@#$ed up to make this a hassle */ static void camel_dlist_init(CamelDList *v) { - v->head = (CamelDListNode *)&v->tail; - v->tail = NULL; - v->tailpred = (CamelDListNode *)&v->head; + v->head = (CamelDListNode *)&v->terminator; + v->terminator = NULL; + v->tail = (CamelDListNode *)&v->head; } static CamelDListNode *camel_dlist_addhead(CamelDList *l, CamelDListNode *n) @@ -176,10 +176,10 @@ static CamelDListNode *camel_dlist_addhead(CamelDList *l, CamelDListNode *n) static CamelDListNode *camel_dlist_addtail(CamelDList *l, CamelDListNode *n) { - n->next = (CamelDListNode *)&l->tail; - n->prev = l->tailpred; - l->tailpred->next = n; - l->tailpred = n; + n->next = (CamelDListNode *)&l->terminator; + n->prev = l->tail; + l->tail->next = n; + l->tail = n; return n; } @@ -467,7 +467,7 @@ camel_iconv_open (const gchar *oto, const gchar *ofrom) if (ic) { camel_dlist_remove((CamelDListNode *)ic); } else { - struct _iconv_cache *last = (struct _iconv_cache *)iconv_cache_list.tailpred; + struct _iconv_cache *last = (struct _iconv_cache *)iconv_cache_list.tail; struct _iconv_cache *prev; prev = last->prev; @@ -496,7 +496,7 @@ camel_iconv_open (const gchar *oto, const gchar *ofrom) camel_dlist_addhead(&iconv_cache_list, (CamelDListNode *)ic); /* If we have a free iconv, use it */ - in = (struct _iconv_cache_node *)ic->open.tailpred; + in = (struct _iconv_cache_node *)ic->open.tail; if (in->prev && !in->busy) { cd(printf("using existing iconv converter '%s'\n", ic->conv)); ip = in->ip; diff --git a/camel/camel-list-utils.c b/camel/camel-list-utils.c index bf9489b..2e9b7e5 100644 --- a/camel/camel-list-utils.c +++ b/camel/camel-list-utils.c @@ -38,9 +38,9 @@ void camel_dlist_init (CamelDList *v) { - v->head = (CamelDListNode *)&v->tail; - v->tail = NULL; - v->tailpred = (CamelDListNode *)&v->head; + v->head = (CamelDListNode *)&v->terminator; + v->terminator = NULL; + v->tail = (CamelDListNode *)&v->head; } /** @@ -74,10 +74,10 @@ camel_dlist_addhead (CamelDList *l, CamelDListNode *n) CamelDListNode * camel_dlist_addtail (CamelDList *l, CamelDListNode *n) { - n->next = (CamelDListNode *)&l->tail; - n->prev = l->tailpred; - l->tailpred->next = n; - l->tailpred = n; + n->next = (CamelDListNode *)&l->terminator; + n->prev = l->tail; + l->tail->next = n; + l->tail = n; return n; } @@ -135,11 +135,11 @@ camel_dlist_remtail (CamelDList *l) { CamelDListNode *n, *np; - n = l->tailpred; + n = l->tail; np = n->prev; if (np) { np->next = n->next; - l->tailpred = np; + l->tail = np; return n; } return NULL; @@ -156,7 +156,7 @@ camel_dlist_remtail (CamelDList *l) gint camel_dlist_empty (CamelDList *l) { - return (l->head == (CamelDListNode *)&l->tail); + return (l->head == (CamelDListNode *)&l->terminator); } /** diff --git a/camel/camel-list-utils.h b/camel/camel-list-utils.h index e75ef23..e5cb5f0 100644 --- a/camel/camel-list-utils.h +++ b/camel/camel-list-utils.h @@ -55,8 +55,8 @@ struct _CamelDListNode { * struct _CamelDList - A double-linked list header. * * @head: The head node's next pointer. - * @tail: The tail node's next pointer. - * @tailpred: The previous node to the tail node. + * @terminator: The head's prev and tail's next pointer. + * @tail: The tail node's prev pointer. * * This is the merging of two separate head and tail nodes into a * single structure. i.e. if you ahve a NULL terminated head and tail @@ -68,11 +68,11 @@ struct _CamelDListNode { **/ struct _CamelDList { struct _CamelDListNode *head; + struct _CamelDListNode *terminator; struct _CamelDListNode *tail; - struct _CamelDListNode *tailpred; }; -#define CAMEL_DLIST_INITIALISER(l) { (CamelDListNode *)&l.tail, 0, (CamelDListNode *)&l.head } +#define CAMEL_DLIST_INITIALISER(l) { (CamelDListNode *)&l.terminator, 0, (CamelDListNode *)&l.head } void camel_dlist_init(CamelDList *v); CamelDListNode *camel_dlist_addhead(CamelDList *l, CamelDListNode *n); diff --git a/camel/camel-text-index.c b/camel/camel-text-index.c index f696fd7..e6453b3 100644 --- a/camel/camel-text-index.c +++ b/camel/camel-text-index.c @@ -214,7 +214,7 @@ text_index_add_name_to_word(CamelIndex *idx, const gchar *word, camel_key_t name g_hash_table_insert(p->words, w->word, w); camel_dlist_addhead(&p->word_cache, (CamelDListNode *)w); p->word_cache_count++; - ww = (struct _CamelTextIndexWord *)p->word_cache.tailpred; + ww = (struct _CamelTextIndexWord *)p->word_cache.tail; wp = ww->prev; while (wp && p->word_cache_count > p->word_cache_limit) { io(printf("writing key file entry '%s' [%x]\n", ww->word, ww->data)); diff --git a/libedataserver/e-iconv.c b/libedataserver/e-iconv.c index 411f71c..61f5bd4 100644 --- a/libedataserver/e-iconv.c +++ b/libedataserver/e-iconv.c @@ -60,11 +60,11 @@ typedef struct _EDListNode { typedef struct _EDList { struct _EDListNode *head; + struct _EDListNode *terminator; struct _EDListNode *tail; - struct _EDListNode *tailpred; } EDList; -#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.tail, 0, (EDListNode *)&l.head } +#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.terminator, 0, (EDListNode *)&l.head } struct _iconv_cache_node { struct _iconv_cache_node *next; @@ -157,9 +157,9 @@ static const struct { and g_list's are f@@#$ed up to make this a hassle */ static void e_dlist_init(EDList *v) { - v->head = (EDListNode *)&v->tail; - v->tail = NULL; - v->tailpred = (EDListNode *)&v->head; + v->head = (EDListNode *)&v->terminator; + v->terminator = NULL; + v->tail = (EDListNode *)&v->head; } static EDListNode *e_dlist_addhead(EDList *l, EDListNode *n) @@ -173,10 +173,10 @@ static EDListNode *e_dlist_addhead(EDList *l, EDListNode *n) static EDListNode *e_dlist_addtail(EDList *l, EDListNode *n) { - n->next = (EDListNode *)&l->tail; - n->prev = l->tailpred; - l->tailpred->next = n; - l->tailpred = n; + n->next = (EDListNode *)&l->terminator; + n->prev = l->tail; + l->tail->next = n; + l->tail = n; return n; } @@ -462,7 +462,7 @@ iconv_t e_iconv_open(const gchar *oto, const gchar *ofrom) if (ic) { e_dlist_remove((EDListNode *)ic); } else { - struct _iconv_cache *last = (struct _iconv_cache *)iconv_cache_list.tailpred; + struct _iconv_cache *last = (struct _iconv_cache *)iconv_cache_list.tail; struct _iconv_cache *prev; prev = last->prev; @@ -491,7 +491,7 @@ iconv_t e_iconv_open(const gchar *oto, const gchar *ofrom) e_dlist_addhead(&iconv_cache_list, (EDListNode *)ic); /* If we have a free iconv, use it */ - in = (struct _iconv_cache_node *)ic->open.tailpred; + in = (struct _iconv_cache_node *)ic->open.tail; if (in->prev && !in->busy) { cd(printf("using existing iconv converter '%s'\n", ic->conv)); ip = in->ip; diff --git a/libedataserver/e-msgport.c b/libedataserver/e-msgport.c index 7a2c6ee..861d686 100644 --- a/libedataserver/e-msgport.c +++ b/libedataserver/e-msgport.c @@ -198,9 +198,9 @@ out0: void e_dlist_init(EDList *v) { - v->head = (EDListNode *)&v->tail; - v->tail = NULL; - v->tailpred = (EDListNode *)&v->head; + v->head = (EDListNode *)&v->terminator; + v->terminator = NULL; + v->tail = (EDListNode *)&v->head; } EDListNode *e_dlist_addhead(EDList *l, EDListNode *n) @@ -214,10 +214,10 @@ EDListNode *e_dlist_addhead(EDList *l, EDListNode *n) EDListNode *e_dlist_addtail(EDList *l, EDListNode *n) { - n->next = (EDListNode *)&l->tail; - n->prev = l->tailpred; - l->tailpred->next = n; - l->tailpred = n; + n->next = (EDListNode *)&l->terminator; + n->prev = l->tail; + l->tail->next = n; + l->tail = n; return n; } @@ -246,11 +246,11 @@ EDListNode *e_dlist_remtail(EDList *l) { EDListNode *n, *np; - n = l->tailpred; + n = l->tail; np = n->prev; if (np) { np->next = n->next; - l->tailpred = np; + l->tail = np; return n; } return NULL; @@ -258,7 +258,7 @@ EDListNode *e_dlist_remtail(EDList *l) gint e_dlist_empty(EDList *l) { - return (l->head == (EDListNode *)&l->tail); + return (l->head == (EDListNode *)&l->terminator); } gint e_dlist_length(EDList *l) @@ -437,7 +437,7 @@ em_cache_add(EMCache *emc, EMCacheNode *n) c(printf("inserting node %s\n", n->key)); - old = (EMCacheNode *)emc->lru_list.tailpred; + old = (EMCacheNode *)emc->lru_list.tail; prev = old->prev; while (prev && old->stamp < now - emc->timeout) { if (old->ref_count == 0) { diff --git a/libedataserver/e-msgport.h b/libedataserver/e-msgport.h index 6e1573e..fbb9098 100644 --- a/libedataserver/e-msgport.h +++ b/libedataserver/e-msgport.h @@ -13,11 +13,11 @@ typedef struct _EDListNode { typedef struct _EDList { struct _EDListNode *head; + struct _EDListNode *terminator; struct _EDListNode *tail; - struct _EDListNode *tailpred; } EDList; -#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.tail, NULL, (EDListNode *)&l.head } +#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.terminator, NULL, (EDListNode *)&l.head } void e_dlist_init(EDList *v); EDListNode *e_dlist_addhead(EDList *l, EDListNode *n); -- 1.6.5
Attachment:
signature.asc
Description: This is a digitally signed message part