dovecot-2.0: Use array_foreach*() in some useful places.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Oct 8 20:02:42 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/c610321584ca
changeset: 10000:c610321584ca
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 08 13:02:25 2009 -0400
description:
Use array_foreach*() in some useful places.
diffstat:
30 files changed, 197 insertions(+), 300 deletions(-)
src/dict/dict-commands.c | 10 -
src/dict/dict-connection.c | 8 -
src/dsync/dsync-brain-msgs.c | 8 -
src/dsync/dsync-brain.c | 12 -
src/imap/imap-client.c | 10 -
src/imap/imap-fetch.c | 33 ++---
src/lib-auth/auth-client.c | 10 -
src/lib-index/mail-index-fsck.c | 10 -
src/lib-index/mail-index-map-read.c | 9 -
src/lib-index/mail-index-map.c | 14 --
src/lib-index/mail-index-modseq.c | 16 --
src/lib-index/mail-index-sync-ext.c | 15 --
src/lib-index/mail-index-sync-update.c | 4
src/lib-index/mail-index-sync.c | 15 --
src/lib-index/mail-index-transaction-finish.c | 23 +--
src/lib-index/mail-index-transaction-sort-appends.c | 14 --
src/lib-index/mail-index-transaction-update.c | 118 ++++++++-----------
src/lib-index/mail-index-view-sync.c | 12 -
src/lib-sql/driver-mysql.c | 14 --
src/lib-sql/driver-pgsql.c | 10 -
src/lib-storage/index/index-search-result.c | 6
src/lib-storage/index/index-sort-string.c | 8 -
src/lib-storage/index/index-sync-search.c | 8 -
src/lib/seq-range-array.c | 25 +---
src/lmtp/commands.c | 22 +--
src/lmtp/lmtp-proxy.c | 8 -
src/plugins/acl/acl-backend-vfile-acllist.c | 10 -
src/plugins/fts-squat/squat-trie.c | 8 -
src/plugins/quota/quota-storage.c | 8 -
src/plugins/quota/quota.c | 29 +---
diffs (truncated from 1085 to 300 lines):
diff -r 2c703e55d247 -r c610321584ca src/dict/dict-commands.c
--- a/src/dict/dict-commands.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/dict/dict-commands.c Thu Oct 08 13:02:25 2009 -0400
@@ -103,16 +103,14 @@ dict_connection_transaction_lookup(struc
dict_connection_transaction_lookup(struct dict_connection *conn,
unsigned int id)
{
- struct dict_connection_transaction *transactions;
- unsigned int i, count;
+ struct dict_connection_transaction *transaction;
if (!array_is_created(&conn->transactions))
return NULL;
- transactions = array_get_modifiable(&conn->transactions, &count);
- for (i = 0; i < count; i++) {
- if (transactions[i].id == id)
- return &transactions[i];
+ array_foreach_modifiable(&conn->transactions, transaction) {
+ if (transaction->id == id)
+ return transaction;
}
return NULL;
}
diff -r 2c703e55d247 -r c610321584ca src/dict/dict-connection.c
--- a/src/dict/dict-connection.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/dict/dict-connection.c Thu Oct 08 13:02:25 2009 -0400
@@ -155,15 +155,13 @@ struct dict_connection *dict_connection_
void dict_connection_destroy(struct dict_connection *conn)
{
- struct dict_connection_transaction *transactions;
- unsigned int i, count;
+ struct dict_connection_transaction *transaction;
DLLIST_REMOVE(&dict_connections, conn);
if (array_is_created(&conn->transactions)) {
- transactions = array_get_modifiable(&conn->transactions, &count);
- for (i = 0; i < count; i++)
- dict_transaction_rollback(&transactions[i].ctx);
+ array_foreach_modifiable(&conn->transactions, transaction)
+ dict_transaction_rollback(&transaction->ctx);
array_free(&conn->transactions);
}
diff -r 2c703e55d247 -r c610321584ca src/dsync/dsync-brain-msgs.c
--- a/src/dsync/dsync-brain-msgs.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/dsync/dsync-brain-msgs.c Thu Oct 08 13:02:25 2009 -0400
@@ -333,13 +333,11 @@ get_mailbox_guids(const ARRAY_TYPE(dsync
get_mailbox_guids(const ARRAY_TYPE(dsync_brain_mailbox) *mailboxes,
ARRAY_TYPE(mailbox_guid) *guids)
{
- const struct dsync_brain_mailbox *brain_boxes;
- unsigned int i, count;
+ const struct dsync_brain_mailbox *brain_box;
t_array_init(guids, array_count(mailboxes));
- brain_boxes = array_get(mailboxes, &count);
- for (i = 0; i < count; i++)
- array_append(guids, &brain_boxes[i].box.mailbox_guid, 1);
+ array_foreach(mailboxes, brain_box)
+ array_append(guids, &brain_box->box.mailbox_guid, 1);
}
struct dsync_brain_mailbox_sync *
diff -r 2c703e55d247 -r c610321584ca src/dsync/dsync-brain.c
--- a/src/dsync/dsync-brain.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/dsync/dsync-brain.c Thu Oct 08 13:02:25 2009 -0400
@@ -344,17 +344,13 @@ static void
static void
dsync_brain_msg_sync_update_mailbox(struct dsync_brain *brain)
{
- const struct dsync_brain_mailbox *mailboxes;
- unsigned int i, count;
+ const struct dsync_brain_mailbox *mailbox;
/* FIXME: handle different hierarchy separators? */
- mailboxes = array_get(&brain->mailbox_sync->mailboxes, &count);
- for (i = 0; i < count; i++) {
- dsync_worker_update_mailbox(brain->src_worker,
- &mailboxes[i].box);
- dsync_worker_update_mailbox(brain->dest_worker,
- &mailboxes[i].box);
+ array_foreach(&brain->mailbox_sync->mailboxes, mailbox) {
+ dsync_worker_update_mailbox(brain->src_worker, &mailbox->box);
+ dsync_worker_update_mailbox(brain->dest_worker, &mailbox->box);
}
}
diff -r 2c703e55d247 -r c610321584ca src/imap/imap-client.c
--- a/src/imap/imap-client.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/imap/imap-client.c Thu Oct 08 13:02:25 2009 -0400
@@ -927,16 +927,14 @@ client_search_update_lookup(struct clien
void client_search_updates_free(struct client *client)
{
- struct imap_search_update *updates;
- unsigned int i, count;
+ struct imap_search_update *update;
if (!array_is_created(&client->search_updates))
return;
- updates = array_get_modifiable(&client->search_updates, &count);
- for (i = 0; i < count; i++) {
- i_free(updates[i].tag);
- mailbox_search_result_free(&updates[i].result);
+ array_foreach_modifiable(&client->search_updates, update) {
+ i_free(update->tag);
+ mailbox_search_result_free(&update->result);
}
array_clear(&client->search_updates);
}
diff -r 2c703e55d247 -r c610321584ca src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/imap/imap-fetch.c Thu Oct 08 13:02:25 2009 -0400
@@ -117,17 +117,14 @@ void imap_fetch_add_handler(struct imap_
client requested them. This is especially useful to get UID
returned first, which some clients rely on..
*/
- const struct imap_fetch_context_handler *handlers;
+ const struct imap_fetch_context_handler *ctx_handler;
struct imap_fetch_context_handler h;
- unsigned int i, size;
if (context == NULL) {
/* don't allow duplicate handlers */
- handlers = array_get(&ctx->handlers, &size);
-
- for (i = 0; i < size; i++) {
- if (handlers[i].handler == handler &&
- handlers[i].context == NULL)
+ array_foreach(&ctx->handlers, ctx_handler) {
+ if (ctx_handler->handler == handler &&
+ ctx_handler->context == NULL)
return;
}
}
@@ -259,12 +256,10 @@ mailbox_expunge_to_range(const ARRAY_TYP
mailbox_expunge_to_range(const ARRAY_TYPE(mailbox_expunge_rec) *input,
ARRAY_TYPE(seq_range) *output)
{
- const struct mailbox_expunge_rec *expunges;
- unsigned int i, count;
-
- expunges = array_get(input, &count);
- for (i = 0; i < count; i++)
- seq_range_array_add(output, 0, expunges[i].uid);
+ const struct mailbox_expunge_rec *expunge;
+
+ array_foreach(input, expunge)
+ seq_range_array_add(output, 0, expunge->uid);
}
static int
@@ -530,13 +525,11 @@ int imap_fetch_more(struct imap_fetch_co
int imap_fetch_deinit(struct imap_fetch_context *ctx)
{
- const struct imap_fetch_context_handler *handlers;
- unsigned int i, count;
-
- handlers = array_get(&ctx->handlers, &count);
- for (i = 0; i < count; i++) {
- if (handlers[i].want_deinit)
- handlers[i].handler(ctx, NULL, handlers[i].context);
+ const struct imap_fetch_context_handler *handler;
+
+ array_foreach(&ctx->handlers, handler) {
+ if (handler->want_deinit)
+ handler->handler(ctx, NULL, handler->context);
}
if (!ctx->line_finished) {
diff -r 2c703e55d247 -r c610321584ca src/lib-auth/auth-client.c
--- a/src/lib-auth/auth-client.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/lib-auth/auth-client.c Thu Oct 08 13:02:25 2009 -0400
@@ -54,13 +54,11 @@ const struct auth_mech_desc *
const struct auth_mech_desc *
auth_client_find_mech(struct auth_client *client, const char *name)
{
- const struct auth_mech_desc *mechs;
- unsigned int i, count;
+ const struct auth_mech_desc *mech;
- mechs = array_get(&client->conn->available_auth_mechs, &count);
- for (i = 0; i < count; i++) {
- if (strcasecmp(mechs[i].name, name) == 0)
- return &mechs[i];
+ array_foreach(&client->conn->available_auth_mechs, mech) {
+ if (strcasecmp(mech->name, name) == 0)
+ return mech;
}
return NULL;
}
diff -r 2c703e55d247 -r c610321584ca src/lib-index/mail-index-fsck.c
--- a/src/lib-index/mail-index-fsck.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/lib-index/mail-index-fsck.c Thu Oct 08 13:02:25 2009 -0400
@@ -68,12 +68,10 @@ static bool
static bool
array_has_name(const ARRAY_TYPE(const_string) *names, const char *name)
{
- const char *const *str;
- unsigned int i, count;
-
- str = array_get(names, &count);
- for (i = 0; i < count; i++) {
- if (strcmp(str[i], name) == 0)
+ const char *const *namep;
+
+ array_foreach(names, namep) {
+ if (strcmp(*namep, name) == 0)
return TRUE;
}
return FALSE;
diff -r 2c703e55d247 -r c610321584ca src/lib-index/mail-index-map-read.c
--- a/src/lib-index/mail-index-map-read.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/lib-index/mail-index-map-read.c Thu Oct 08 13:02:25 2009 -0400
@@ -239,16 +239,15 @@ static int mail_index_read_map(struct ma
unsigned int *lock_id)
{
struct mail_index *index = map->index;
- mail_index_sync_lost_handler_t *const *handlers;
+ mail_index_sync_lost_handler_t *const *handlerp;
struct stat st;
- unsigned int i, count;
+ unsigned int i;
int ret;
bool try_retry, retry;
/* notify all "sync lost" handlers */
- handlers = array_get(&index->sync_lost_handlers, &count);
- for (i = 0; i < count; i++)
- (*handlers[i])(index);
+ array_foreach(&index->sync_lost_handlers, handlerp)
+ (**handlerp)(index);
for (i = 0;; i++) {
try_retry = i < MAIL_INDEX_ESTALE_RETRY_COUNT;
diff -r 2c703e55d247 -r c610321584ca src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/lib-index/mail-index-map.c Thu Oct 08 13:02:25 2009 -0400
@@ -356,8 +356,8 @@ struct mail_index_map *mail_index_map_cl
struct mail_index_map *mail_index_map_clone(const struct mail_index_map *map)
{
struct mail_index_map *mem_map;
- struct mail_index_ext *extensions;
- unsigned int i, count;
+ struct mail_index_ext *ext;
+ unsigned int count;
mem_map = i_new(struct mail_index_map, 1);
mem_map->index = map->index;
@@ -386,13 +386,11 @@ struct mail_index_map *mail_index_map_cl
array_append_array(&mem_map->ext_id_map, &map->ext_id_map);
/* fix the name pointers to use our own pool */
- extensions = array_get_modifiable(&mem_map->extensions, &count);
- for (i = 0; i < count; i++) {
- i_assert(extensions[i].record_offset +
- extensions[i].record_size <=
+ array_foreach_modifiable(&mem_map->extensions, ext) {
+ i_assert(ext->record_offset + ext->record_size <=
mem_map->hdr.record_size);
- extensions[i].name = p_strdup(mem_map->extension_pool,
- extensions[i].name);
+ ext->name = p_strdup(mem_map->extension_pool,
+ ext->name);
}
}
diff -r 2c703e55d247 -r c610321584ca src/lib-index/mail-index-modseq.c
--- a/src/lib-index/mail-index-modseq.c Thu Oct 08 11:52:47 2009 -0400
+++ b/src/lib-index/mail-index-modseq.c Thu Oct 08 13:02:25 2009 -0400
@@ -547,17 +547,15 @@ void mail_index_modseq_expunge(struct ma
uint32_t seq1, uint32_t seq2)
{
struct metadata_modseqs *metadata;
- unsigned int i, count;
uint64_t modseq;
if (ctx->mmap == NULL)
return;
seq1--;
- metadata = array_get_modifiable(&ctx->mmap->metadata_modseqs, &count);
- for (i = 0; i < count; i++) {
- if (array_is_created(&metadata[i].modseqs))
- array_delete(&metadata[i].modseqs, seq1, seq2-seq1);
+ array_foreach_modifiable(&ctx->mmap->metadata_modseqs, metadata) {
+ if (array_is_created(&metadata->modseqs))
+ array_delete(&metadata->modseqs, seq1, seq2-seq1);
}
modseq = mail_transaction_log_view_get_prev_modseq(ctx->log_view);
@@ -666,14 +664,12 @@ void mail_index_map_modseq_free(struct m
{
struct mail_index_map_modseq *mmap = *_mmap;
More information about the dovecot-cvs
mailing list