dovecot-2.0: imap code cleanup: Use array instead of buffer for ...
dovecot at dovecot.org
dovecot at dovecot.org
Thu May 21 19:59:35 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/d6eda52bd74b
changeset: 9344:d6eda52bd74b
user: Timo Sirainen <tss at iki.fi>
date: Thu May 21 12:59:30 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 fe0ee823db41 -r d6eda52bd74b src/imap/imap-fetch.c
--- a/src/imap/imap-fetch.c Thu May 21 12:55:57 2009 -0400
+++ b/src/imap/imap-fetch.c Thu May 21 12:59:30 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