]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexes: Don't add ext-intros unnecessarily twice for ext-rec updates.
authorTimo Sirainen <tss@iki.fi>
Tue, 10 Mar 2009 00:51:35 +0000 (20:51 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 10 Mar 2009 00:51:35 +0000 (20:51 -0400)
Also did some code cleanups.

--HG--
branch : HEAD

src/lib-index/mail-transaction-log-append.c

index b63a0b8566b86389ede43b3ad676450ff8617871..4fafc1627449920f52590cb93a732aa202fb2524 100644 (file)
@@ -236,7 +236,7 @@ static void log_append_ext_intro(struct log_append_context *ctx,
 {
        struct mail_index_transaction *t = ctx->trans;
        const struct mail_index_registered_ext *rext;
-        struct mail_transaction_ext_intro *intro;
+        struct mail_transaction_ext_intro *intro, *resizes;
        buffer_t *buf;
        uint32_t idx;
        unsigned int count;
@@ -251,16 +251,16 @@ static void log_append_ext_intro(struct log_append_context *ctx,
 
        rext = array_idx(&t->view->index->extensions, ext_id);
        if (!array_is_created(&t->ext_resizes)) {
-               intro = NULL;
+               resizes = NULL;
                count = 0;
        } else {
-               intro = array_get_modifiable(&t->ext_resizes, &count);
+               resizes = array_get_modifiable(&t->ext_resizes, &count);
        }
 
        buf = buffer_create_dynamic(pool_datastack_create(), 128);
-       if (ext_id < count && intro[ext_id].name_size != 0) {
-               /* we're resizing it */
-               intro += ext_id;
+       if (ext_id < count && resizes[ext_id].name_size != 0) {
+               /* we're resizing the extension. use the resize struct. */
+               intro = &resizes[ext_id];
 
                i_assert(intro->ext_id == idx);
                intro->name_size = idx != (uint32_t)-1 ? 0 :
@@ -344,21 +344,12 @@ mail_transaction_log_append_ext_intros(struct log_append_context *ctx)
         const struct mail_transaction_ext_intro *resize;
        const struct mail_index_transaction_ext_hdr_update *hdrs;
        struct mail_transaction_ext_reset ext_reset;
-       unsigned int update_count, resize_count, ext_count = 0;
+       unsigned int resize_count, ext_count = 0;
        unsigned int hdrs_count, reset_id_count, reset_count;
        uint32_t ext_id, reset_id;
        const struct mail_transaction_ext_reset *reset;
        const uint32_t *reset_ids;
-       const ARRAY_TYPE(seq_array) *update;
-       buffer_t *buf;
-
-       if (!array_is_created(&t->ext_rec_updates)) {
-               update = NULL;
-               update_count = 0;
-       } else {
-               update = array_get(&t->ext_rec_updates, &update_count);
-               ext_count = update_count;
-       }
+       buffer_t *reset_buf;
 
        if (!array_is_created(&t->ext_resizes)) {
                resize = NULL;
@@ -395,9 +386,9 @@ mail_transaction_log_append_ext_intros(struct log_append_context *ctx)
        }
 
        memset(&ext_reset, 0, sizeof(ext_reset));
-       buf = buffer_create_data(pool_datastack_create(),
-                                &ext_reset, sizeof(ext_reset));
-       buffer_set_used_size(buf, sizeof(ext_reset));
+       reset_buf = buffer_create_data(pool_datastack_create(),
+                                      &ext_reset, sizeof(ext_reset));
+       buffer_set_used_size(reset_buf, sizeof(ext_reset));
 
        for (ext_id = 0; ext_id < ext_count; ext_id++) {
                if (ext_id < reset_count)
@@ -405,19 +396,22 @@ mail_transaction_log_append_ext_intros(struct log_append_context *ctx)
                else
                        ext_reset.new_reset_id = 0;
                if ((ext_id < resize_count && resize[ext_id].name_size) ||
-                   (ext_id < update_count &&
-                    array_is_created(&update[ext_id])) ||
                    ext_reset.new_reset_id != 0 ||
                    (ext_id < hdrs_count && hdrs[ext_id].alloc_size > 0)) {
-                       reset_id = ext_id < reset_id_count &&
-                               ext_reset.new_reset_id == 0 ?
-                               reset_ids[ext_id] : 0;
+                       if (ext_reset.new_reset_id != 0) {
+                               /* we're going to reset this extension
+                                  immediately after the intro */
+                               reset_id = 0;
+                       } else {
+                               reset_id = ext_id < reset_id_count ?
+                                       reset_ids[ext_id] : 0;
+                       }
                        log_append_ext_intro(ctx, ext_id, reset_id);
                }
                if (ext_reset.new_reset_id != 0) {
                        i_assert(ext_id < reset_id_count &&
                                 ext_reset.new_reset_id == reset_ids[ext_id]);
-                       log_append_buffer(ctx, buf, NULL,
+                       log_append_buffer(ctx, reset_buf, NULL,
                                          MAIL_TRANSACTION_EXT_RESET);
                }
                if (ext_id < hdrs_count && hdrs[ext_id].alloc_size > 0) {