[dovecot-cvs] dovecot/src/lib-storage mail-thread.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Sat Jan 11 17:29:49 EET 2003


Update of /home/cvs/dovecot/src/lib-storage
In directory danu:/tmp/cvs-serv7725/src/lib-storage

Modified Files:
	mail-thread.c 
Log Message:
Rewrote hash table code, works with less memory now. Also some memory
allocation fixes to thread extension code.



Index: mail-thread.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/mail-thread.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mail-thread.c	10 Jan 2003 01:48:06 -0000	1.3
+++ mail-thread.c	11 Jan 2003 15:29:47 -0000	1.4
@@ -67,7 +67,7 @@
 
 struct mail_thread_context {
 	pool_t pool;
-	pool_t str_pool; /* for node->msgid and root_info->base_subject */
+	pool_t temp_pool;
 
 	struct hash_table *msgid_hash;
 	struct hash_table *subject_hash;
@@ -94,12 +94,11 @@
 
 	ctx = p_new(pool, struct mail_thread_context, 1);
 	ctx->pool = pool;
-	ctx->str_pool =
-		pool_alloconly_create("mail_thread_context strings",
-				      sizeof(struct node) *
-				      APPROX_MSG_COUNT * APPROX_MSGID_SIZE);
-	ctx->msgid_hash = hash_create(default_pool,
-				      APPROX_MSGID_SIZE*2, str_hash,
+	ctx->temp_pool = pool_alloconly_create("mail_thread_context temp",
+					       APPROX_MSG_COUNT *
+					       APPROX_MSGID_SIZE);
+	ctx->msgid_hash = hash_create(default_pool, ctx->temp_pool,
+				      APPROX_MSG_COUNT*2, str_hash,
 				      (HashCompareFunc)strcmp);
 	ctx->callbacks = callbacks;
 	ctx->callback_context = callback_context;
@@ -113,7 +112,8 @@
 		hash_destroy(ctx->msgid_hash);
 	if (ctx->subject_hash != NULL)
 		hash_destroy(ctx->subject_hash);
-	pool_unref(ctx->str_pool);
+
+	pool_unref(ctx->temp_pool);
 	pool_unref(ctx->pool);
 }
 
@@ -132,7 +132,7 @@
 	struct node *node;
 
 	node = p_new(ctx->pool, struct node, 1);
-	node->u.msgid = p_strdup(ctx->str_pool, msgid);
+	node->u.msgid = p_strdup(ctx->temp_pool, msgid);
 
 	hash_insert(ctx->msgid_hash, node->u.msgid, node);
 	return node;
@@ -558,7 +558,7 @@
 		return;
 
 	if (!hash_lookup_full(ctx->subject_hash, subject, &key, &value)) {
-		hash_subject = p_strdup(ctx->str_pool, subject);
+		hash_subject = p_strdup(ctx->temp_pool, subject);
 		hash_insert(ctx->subject_hash, hash_subject, node);
 	} else {
 		hash_subject = key;
@@ -582,9 +582,8 @@
 
 	cb = ctx->callbacks;
 	ctx->subject_hash =
-		hash_create(default_pool, ctx->root_count * 2, str_hash,
-			    (HashCompareFunc)strcmp);
-
+		hash_create(default_pool, ctx->temp_pool, ctx->root_count * 2,
+			    str_hash, (HashCompareFunc)strcmp);
 	for (node = ctx->root_nodes; node != NULL; node = node->next) {
 		if (!NODE_IS_DUMMY(node))
 			id = node->id;
@@ -834,17 +833,19 @@
 {
 	struct node *node;
 
-	/* drop the memory allocated for message-IDs, reuse their memory
-	   for base subjects */
-	p_clear(ctx->str_pool);
-
 	/* (2) save root nodes and drop the msgids */
 	hash_foreach(ctx->msgid_hash, save_root_cb, ctx);
+
+	/* drop the memory allocated for message-IDs and msgid_hash,
+	   reuse their memory for base subjects */
 	hash_destroy(ctx->msgid_hash);
 	ctx->msgid_hash = NULL;
 
+	p_clear(ctx->temp_pool);
+
 	if (ctx->root_nodes == NULL) {
 		/* no messages */
+		mail_thread_deinit(ctx);
 		return;
 	}
 




More information about the dovecot-cvs mailing list