[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.230.2.5, 1.230.2.6

cras at dovecot.org cras at dovecot.org
Sun Jul 23 17:23:00 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv31920

Modified Files:
      Tag: branch_1_0
	mail-index.c 
Log Message:
Small memory usage optimization.



Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.230.2.5
retrieving revision 1.230.2.6
diff -u -d -r1.230.2.5 -r1.230.2.6
--- mail-index.c	17 Jun 2006 13:42:36 -0000	1.230.2.5
+++ mail-index.c	23 Jul 2006 14:22:58 -0000	1.230.2.6
@@ -179,18 +179,28 @@
 					unsigned int initial_count)
 {
 #define EXTENSION_NAME_APPROX_LEN 20
+#define EXT_GLOBAL_ALLOC_SIZE ((sizeof(array_t) + BUFFER_APPROX_SIZE) * 2)
+#define EXT_PER_ALLOC_SIZE \
+	(EXTENSION_NAME_APPROX_LEN + \
+	 sizeof(struct mail_index_ext) + sizeof(uint32_t))
 	size_t size;
 
 	if (map->extension_pool == NULL) {
-		size = (sizeof(array_t) + BUFFER_APPROX_SIZE) * 2 +
-			initial_count * (EXTENSION_NAME_APPROX_LEN +
-					 sizeof(struct mail_index_ext) +
-					 sizeof(uint32_t));
+		size = EXT_GLOBAL_ALLOC_SIZE +
+			initial_count * EXT_PER_ALLOC_SIZE;
 		map->extension_pool =
 			pool_alloconly_create("extensions",
 					      nearest_power(size));
 	} else {
 		p_clear(map->extension_pool);
+
+		/* try to use the existing pool's size for initial_count so
+		   we don't grow it unneededly */
+		size = p_get_max_easy_alloc_size(map->extension_pool);
+		if (size > EXT_GLOBAL_ALLOC_SIZE + EXT_PER_ALLOC_SIZE) {
+			initial_count = (size - EXT_GLOBAL_ALLOC_SIZE) /
+				EXT_PER_ALLOC_SIZE;
+		}
 	}
 
 	ARRAY_CREATE(&map->extensions, map->extension_pool,



More information about the dovecot-cvs mailing list