[dovecot-cvs] dovecot/src/lib-index mail-index.c,1.238,1.239
cras at dovecot.org
cras at dovecot.org
Sun Jul 23 17:23:03 EEST 2006
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv1027
Modified Files:
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.238
retrieving revision 1.239
diff -u -d -r1.238 -r1.239
--- mail-index.c 11 Jul 2006 16:02:42 -0000 1.238
+++ mail-index.c 23 Jul 2006 14:23:00 -0000 1.239
@@ -187,18 +187,29 @@
unsigned int initial_count)
{
#define EXTENSION_NAME_APPROX_LEN 20
+#define EXT_GLOBAL_ALLOC_SIZE \
+ ((sizeof(map->extensions) + 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(map->extensions) + 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