dovecot-1.2: imap code cleanup: Use array instead of buffer for ...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 21 19:59:22 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/43f15920dbaa
changeset: 9072:43f15920dbaa
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 21 12:59:17 2009 -0400
description:
imap code cleanup: Use array instead of buffer for storing fetch handlers.

diffstat:

1 file changed, 16 insertions(+), 16 deletions(-)
src/imap/imap-fetch.c |   32 ++++++++++++++++----------------

diffs (67 lines):

diff -r 106e4e3dccbc -r 43f15920dbaa src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c	Thu May 21 12:55:06 2009 -0400
+++ b/src/imap/imap-fetch.c	Thu May 21 12:59:17 2009 -0400
@@ -22,7 +22,7 @@
 #define ENVELOPE_NIL_REPLY \
 	"(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)"
 
-static buffer_t *fetch_handlers;
+static ARRAY_DEFINE(fetch_handlers, struct imap_fetch_handler);
 
 static int imap_fetch_handler_cmp(const void *p1, const void *p2)
 {
@@ -34,13 +34,13 @@ void imap_fetch_handlers_register(const 
 void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers,
 				  size_t count)
 {
-	void *data;
-	size_t size;
-
-	buffer_append(fetch_handlers, handlers, sizeof(*handlers) * count);
-
-	data = buffer_get_modifiable_data(fetch_handlers, &size);
-	qsort(data, size / sizeof(*handlers), sizeof(*handlers),
+	struct imap_fetch_handler *all_handlers;
+	unsigned int all_count;
+
+	array_append(&fetch_handlers, handlers, count);
+
+	all_handlers = array_get_modifiable(&fetch_handlers, &all_count);
+	qsort(all_handlers, all_count, sizeof(*all_handlers),
 	      imap_fetch_handler_cmp);
 }
 
@@ -64,12 +64,12 @@ bool imap_fetch_init_handler(struct imap
 bool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name,
 			     const struct imap_arg **args)
 {
-	const struct imap_fetch_handler *handler;
-
-	handler = bsearch(name, fetch_handlers->data,
-			  fetch_handlers->used /
+	const struct imap_fetch_handler *handler, *handlers;
+	unsigned int count;
+
+	handlers = array_get_modifiable(&fetch_handlers, &count);
+	handler = bsearch(name, handlers, count,
 			  sizeof(struct imap_fetch_handler),
-                          sizeof(struct imap_fetch_handler),
 			  imap_fetch_handler_bsearch);
 	if (handler == NULL) {
 		client_send_command_error(ctx->cmd,
@@ -852,12 +852,12 @@ imap_fetch_default_handlers[] = {
 
 void imap_fetch_handlers_init(void)
 {
-	fetch_handlers = buffer_create_dynamic(default_pool, 128);
+	i_array_init(&fetch_handlers, 32);
 	imap_fetch_handlers_register(imap_fetch_default_handlers,
 				     N_ELEMENTS(imap_fetch_default_handlers));
 }
 
 void imap_fetch_handlers_deinit(void)
 {
-	buffer_free(&fetch_handlers);
-}
+	array_free(&fetch_handlers);
+}


More information about the dovecot-cvs mailing list