From fe4cb702514ce8d29dc3704a9c7a899e98a6319e Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Thu, 16 May 2019 16:42:05 +0000 Subject: [PATCH] Remove "next" pointer from struct Address: conversion to TAILQ is complete --- address/address.c | 44 --------------------------- address/address.h | 3 -- copy.c | 11 +++---- hcache/serialize.c | 8 ++--- test/address/mutt_addr_for_display.c | 1 - test/address/mutt_addr_write_single.c | 1 - 6 files changed, 7 insertions(+), 61 deletions(-) diff --git a/address/address.c b/address/address.c index 0e7b84ccd..e054680b2 100644 --- a/address/address.c +++ b/address/address.c @@ -1379,50 +1379,6 @@ void mutt_addresslist_prepend(struct AddressList *al, struct Address *a) TAILQ_INSERT_HEAD(al, anode, entries); } -/** - * mutt_addr_to_addresslist - Convert a raw list of Address into an AddressList - * @param a Raw list of Address - * @retval ptr AddressList - * - * The Address members are shared between the input argument and the return - * value. - */ -struct AddressList *mutt_addr_to_addresslist(struct Address *a) -{ - struct AddressList *al = mutt_addresslist_new(); - while (a) - { - struct Address *next = a->next; - a->next = NULL; /* canary */ - mutt_addresslist_append(al, a); - a = next; - } - return al; -} - -/** - * mutt_addresslist_to_addr - Convert an AddressList into a raw list of Address - * @param a Reference list an AddressList - * @retval ptr Raw list of Address - * - * The Address members are shared between the input argument and the return - * value. - */ -struct Address *mutt_addresslist_to_addr(struct AddressList *al) -{ - struct Address *a = NULL; - struct AddressNode *an, *tmp; - TAILQ_FOREACH_REVERSE_SAFE(an, al, AddressList, entries, tmp) - { - assert(an->addr->next == NULL); /* canary */ - an->addr->next = a; - a = an->addr; - TAILQ_REMOVE(al, an, entries); - FREE(&an); - } - return a; -} - /** * mutt_addresslist_free_one - Unlinks an AddressNode from an AddressList and * frees the referenced Address diff --git a/address/address.h b/address/address.h index 76331f1af..396b87618 100644 --- a/address/address.h +++ b/address/address.h @@ -37,7 +37,6 @@ struct Address bool group : 1; /**< group mailbox? */ bool is_intl : 1; bool intl_checked : 1; - struct Address *next; }; struct AddressNode @@ -79,9 +78,7 @@ size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, struct Address *mutt_addr_new(void); /* Functions that work on struct AddressList */ -struct AddressList *mutt_addr_to_addresslist(struct Address *a); struct AddressList *mutt_addresslist_new(void); -struct Address *mutt_addresslist_to_addr(struct AddressList *al); void mutt_addresslist_append(struct AddressList *al, struct Address *a); void mutt_addresslist_prepend(struct AddressList *al, struct Address *a); void mutt_addresslist_copy(struct AddressList *dst, const struct AddressList *src, bool prune); diff --git a/copy.c b/copy.c index 642c2f82a..5c8aa7599 100644 --- a/copy.c +++ b/copy.c @@ -965,14 +965,10 @@ static void format_address_header(char **h, struct AddressList *al) struct AddressNode *an = NULL; TAILQ_FOREACH(an, al, entries) { - struct Address *a = an->addr; - struct Address *tmp = a->next; - a->next = NULL; *buf = '\0'; *cbuf = '\0'; *c2buf = '\0'; - const size_t l = mutt_addr_write(buf, sizeof(buf), a, false); - a->next = tmp; + const size_t l = mutt_addr_write(buf, sizeof(buf), an->addr, false); if (an != first && (linelen + l > 74)) { @@ -981,14 +977,15 @@ static void format_address_header(char **h, struct AddressList *al) } else { - if (a->mailbox) + if (an->addr->mailbox) { strcpy(cbuf, " "); linelen++; } linelen += l; } - if (!a->group && TAILQ_NEXT(an, entries) && TAILQ_NEXT(an, entries)->addr->mailbox) + if (!an->addr->group && TAILQ_NEXT(an, entries) && + TAILQ_NEXT(an, entries)->addr->mailbox) { linelen++; buflen++; diff --git a/hcache/serialize.c b/hcache/serialize.c index e76ef367b..e8005bf0b 100644 --- a/hcache/serialize.c +++ b/hcache/serialize.c @@ -211,11 +211,9 @@ unsigned char *serial_dump_address(struct AddressList *al, unsigned char *d, struct AddressNode *an = NULL; TAILQ_FOREACH(an, al, entries) { - struct Address *a = an->addr; - d = serial_dump_char(a->personal, d, off, convert); - d = serial_dump_char(a->mailbox, d, off, false); - d = serial_dump_int(a->group, d, off); - a = a->next; + d = serial_dump_char(an->addr->personal, d, off, convert); + d = serial_dump_char(an->addr->mailbox, d, off, false); + d = serial_dump_int(an->addr->group, d, off); counter++; } diff --git a/test/address/mutt_addr_for_display.c b/test/address/mutt_addr_for_display.c index 2f8cc7fb6..45893c280 100644 --- a/test/address/mutt_addr_for_display.c +++ b/test/address/mutt_addr_for_display.c @@ -43,7 +43,6 @@ void test_mutt_addr_for_display(void) .personal = per, .mailbox = mbx, .group = 0, - .next = NULL, .is_intl = 0, .intl_checked = 0, }; diff --git a/test/address/mutt_addr_write_single.c b/test/address/mutt_addr_write_single.c index 030cd2701..126df6859 100644 --- a/test/address/mutt_addr_write_single.c +++ b/test/address/mutt_addr_write_single.c @@ -52,7 +52,6 @@ void test_mutt_addr_write_single(void) .personal = per, .mailbox = mbx, .group = 0, - .next = NULL, .is_intl = 0, .intl_checked = 0, }; -- 2.40.0