dovecot-2.2: indexer: Use array.h API instead of writing our own.

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 3 19:27:50 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/165564cc0e0e
changeset: 18822:165564cc0e0e
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 03 22:25:28 2015 +0300
description:
indexer: Use array.h API instead of writing our own.
The space savings aren't worth the extra complexity.

diffstat:

 src/indexer/indexer-queue.c |  27 ++++++++++-----------------
 src/indexer/indexer-queue.h |   2 +-
 2 files changed, 11 insertions(+), 18 deletions(-)

diffs (75 lines):

diff -r 588e141980e2 -r 165564cc0e0e src/indexer/indexer-queue.c
--- a/src/indexer/indexer-queue.c	Wed Jun 03 21:50:40 2015 +0300
+++ b/src/indexer/indexer-queue.c	Wed Jun 03 22:25:28 2015 +0300
@@ -1,6 +1,7 @@
 /* Copyright (c) 2011-2015 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "array.h"
 #include "llist.h"
 #include "hash.h"
 #include "indexer-queue.h"
@@ -70,22 +71,12 @@
 
 static void request_add_context(struct indexer_request *request, void *context)
 {
-	unsigned int count = 0;
-
 	if (context == NULL)
 		return;
 
-	if (request->contexts == NULL) {
-		request->contexts = i_new(void *, 2);
-	} else {
-		for (; request->contexts[count] != NULL; count++) ;
-
-		request->contexts =
-			i_realloc(request->contexts,
-				  sizeof(*request->contexts) * (count + 1),
-				  sizeof(*request->contexts) * (count + 2));
-	}
-	request->contexts[count] = context;
+	if (!array_is_created(&request->contexts))
+		i_array_init(&request->contexts, 2);
+	array_append(&request->contexts, &context, 1);
 }
 
 static struct indexer_request *
@@ -173,11 +164,12 @@
 					     struct indexer_request *request,
 					     int percentage)
 {
+	void *const *contextp;
 	unsigned int i;
 
-	if (request->contexts != NULL) {
-		for (i = 0; request->contexts[i] != NULL; i++)
-			queue->callback(percentage, request->contexts[i]);
+	for (i = 0; i < array_count(&request->contexts); i++) {
+		contextp = array_idx(&request->contexts, i);
+		queue->callback(percentage, *contextp);
 	}
 }
 
@@ -199,7 +191,8 @@
 	*_request = NULL;
 
 	indexer_queue_request_status_int(queue, request, success ? 100 : -1);
-	i_free(request->contexts);
+	if (array_is_created(&request->contexts))
+		array_free(&request->contexts);
 	i_free(request->username);
 	i_free(request->mailbox);
 	i_free(request);
diff -r 588e141980e2 -r 165564cc0e0e src/indexer/indexer-queue.h
--- a/src/indexer/indexer-queue.h	Wed Jun 03 21:50:40 2015 +0300
+++ b/src/indexer/indexer-queue.h	Wed Jun 03 22:25:28 2015 +0300
@@ -15,7 +15,7 @@
 	/* optimize this mailbox */
 	unsigned int optimize:1;
 
-	void **contexts;
+	ARRAY(void *) contexts;
 };
 
 struct indexer_queue *indexer_queue_init(indexer_status_callback_t *callback);


More information about the dovecot-cvs mailing list