From: Timo Sirainen Date: Thu, 15 Jul 2004 12:26:31 +0000 (+0300) Subject: Delay memory allocations for cache transaction. We don't always need it. X-Git-Tag: 1.1.alpha1~3782 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50c4a9739b55370b1d3950d7b3ec2f7cd2ed5f49;p=thirdparty%2Fdovecot%2Fcore.git Delay memory allocations for cache transaction. We don't always need it. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-cache-transaction.c b/src/lib-index/mail-cache-transaction.c index a9629dcaa6..e9cf3a218a 100644 --- a/src/lib-index/mail-cache-transaction.c +++ b/src/lib-index/mail-cache-transaction.c @@ -45,10 +45,6 @@ mail_cache_get_transaction(struct mail_cache_view *view, ctx->cache = view->cache; ctx->view = view; ctx->trans = t; - ctx->cache_data = - buffer_create_dynamic(system_pool, 32768, (size_t)-1); - ctx->cache_data_seq = - buffer_create_dynamic(system_pool, 256, (size_t)-1); ctx->reservations = buffer_create_dynamic(system_pool, 256, (size_t)-1); @@ -64,8 +60,10 @@ static void mail_cache_transaction_free(struct mail_cache_transaction_ctx *ctx) ctx->view->transaction = NULL; ctx->view->trans_seq1 = ctx->view->trans_seq2 = 0; - buffer_free(ctx->cache_data); - buffer_free(ctx->cache_data_seq); + if (ctx->cache_data != NULL) + buffer_free(ctx->cache_data); + if (ctx->cache_data_seq != NULL) + buffer_free(ctx->cache_data_seq); buffer_free(ctx->reservations); i_free(ctx); } @@ -421,6 +419,11 @@ mail_cache_transaction_switch_seq(struct mail_cache_transaction_ctx *ctx) buffer_append(ctx->cache_data_seq, &ctx->prev_seq, sizeof(ctx->prev_seq)); ctx->prev_pos = size; + } else if (ctx->cache_data == NULL) { + ctx->cache_data = + buffer_create_dynamic(system_pool, 32768, (size_t)-1); + ctx->cache_data_seq = + buffer_create_dynamic(system_pool, 256, (size_t)-1); } memset(&new_rec, 0, sizeof(new_rec));