[dovecot-cvs] dovecot/src/lib mempool-alloconly.c, 1.35.2.4, 1.35.2.5 mempool-datastack.c, 1.12, 1.12.2.1 mempool-system.c, 1.18.2.1, 1.18.2.2 mempool-unsafe-datastack.c, 1.3, 1.3.2.1 mempool.h, 1.18.2.1, 1.18.2.2

tss at dovecot.org tss at dovecot.org
Thu Jan 18 15:33:36 UTC 2007


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

Modified Files:
      Tag: branch_1_0
	mempool-alloconly.c mempool-datastack.c mempool-system.c 
	mempool-unsafe-datastack.c mempool.h 
Log Message:
Don't keep the memory pool virtual functions in the pool structure itself,
rather access them via a pointer to a shared virtual function struct.
Reduces memory usage a bit.



Index: mempool-alloconly.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool-alloconly.c,v
retrieving revision 1.35.2.4
retrieving revision 1.35.2.5
diff -u -d -r1.35.2.4 -r1.35.2.5
--- mempool-alloconly.c	28 Dec 2006 23:21:03 -0000	1.35.2.4
+++ mempool-alloconly.c	18 Jan 2007 15:33:34 -0000	1.35.2.5
@@ -54,7 +54,7 @@
 
 static void block_alloc(struct alloconly_pool *pool, size_t size);
 
-static struct pool static_alloconly_pool = {
+static const struct pool_vfuncs static_alloconly_pool_vfuncs = {
 	pool_alloconly_get_name,
 
 	pool_alloconly_ref,
@@ -66,10 +66,14 @@
 	pool_alloconly_realloc,
 
 	pool_alloconly_clear,
-	pool_alloconly_get_max_easy_alloc_size,
+	pool_alloconly_get_max_easy_alloc_size
+};
 
-	TRUE,
-	FALSE
+static const struct pool static_alloconly_pool = {
+	MEMBER(v) &static_alloconly_pool_vfuncs,
+
+	MEMBER(alloconly_pool) TRUE,
+	MEMBER(datastack_pool) FALSE
 };
 
 #ifdef DEBUG

Index: mempool-datastack.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool-datastack.c,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -d -r1.12 -r1.12.2.1
--- mempool-datastack.c	14 Jan 2006 17:23:22 -0000	1.12
+++ mempool-datastack.c	18 Jan 2007 15:33:34 -0000	1.12.2.1
@@ -15,7 +15,7 @@
 static void pool_data_stack_clear(pool_t pool);
 static size_t pool_data_stack_get_max_easy_alloc_size(pool_t pool);
 
-static struct pool static_data_stack_pool = {
+static struct pool_vfuncs static_data_stack_pool_vfuncs = {
 	pool_data_stack_get_name,
 
 	pool_data_stack_ref,
@@ -27,10 +27,14 @@
 	pool_data_stack_realloc,
 
 	pool_data_stack_clear,
-	pool_data_stack_get_max_easy_alloc_size,
+	pool_data_stack_get_max_easy_alloc_size
+};
 
-	TRUE,
-	TRUE
+static const struct pool static_data_stack_pool = {
+	MEMBER(v) &static_data_stack_pool_vfuncs,
+
+	MEMBER(alloconly_pool) TRUE,
+	MEMBER(datastack_pool) TRUE
 };
 
 struct datastack_pool {

Index: mempool-system.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool-system.c,v
retrieving revision 1.18.2.1
retrieving revision 1.18.2.2
diff -u -d -r1.18.2.1 -r1.18.2.2
--- mempool-system.c	10 Sep 2006 17:49:06 -0000	1.18.2.1
+++ mempool-system.c	18 Jan 2007 15:33:34 -0000	1.18.2.2
@@ -23,7 +23,7 @@
 static void pool_system_clear(pool_t pool);
 static size_t pool_system_get_max_easy_alloc_size(pool_t pool);
 
-static struct pool static_system_pool = {
+static struct pool_vfuncs static_system_pool_vfuncs = {
 	pool_system_get_name,
 
 	pool_system_ref,
@@ -35,12 +35,17 @@
 	pool_system_realloc,
 
 	pool_system_clear,
-	pool_system_get_max_easy_alloc_size,
+	pool_system_get_max_easy_alloc_size
+};
 
-	FALSE,
-	FALSE
+static struct pool static_system_pool = {
+	MEMBER(v) &static_system_pool_vfuncs,
+
+	MEMBER(alloconly_pool) FALSE,
+	MEMBER(datastack_pool) FALSE
 };
 
+
 pool_t system_pool = &static_system_pool;
 
 static const char *pool_system_get_name(pool_t pool __attr_unused__)

Index: mempool-unsafe-datastack.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool-unsafe-datastack.c,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -d -r1.3 -r1.3.2.1
--- mempool-unsafe-datastack.c	14 Jan 2006 17:23:22 -0000	1.3
+++ mempool-unsafe-datastack.c	18 Jan 2007 15:33:34 -0000	1.3.2.1
@@ -15,7 +15,7 @@
 static void pool_unsafe_data_stack_clear(pool_t pool);
 static size_t pool_unsafe_data_stack_get_max_easy_alloc_size(pool_t pool);
 
-static struct pool static_unsafe_data_stack_pool = {
+static struct pool_vfuncs static_unsafe_data_stack_pool_vfuncs = {
 	pool_unsafe_data_stack_get_name,
 
 	pool_unsafe_data_stack_ref,
@@ -27,10 +27,14 @@
 	pool_unsafe_data_stack_realloc,
 
 	pool_unsafe_data_stack_clear,
-	pool_unsafe_data_stack_get_max_easy_alloc_size,
+	pool_unsafe_data_stack_get_max_easy_alloc_size
+};
 
-	TRUE,
-	TRUE
+static struct pool static_unsafe_data_stack_pool = {
+	MEMBER(v) &static_unsafe_data_stack_pool_vfuncs,
+
+	MEMBER(alloconly_pool) TRUE,
+	MEMBER(datastack_pool) TRUE
 };
 
 pool_t unsafe_data_stack_pool = &static_unsafe_data_stack_pool;

Index: mempool.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool.h,v
retrieving revision 1.18.2.1
retrieving revision 1.18.2.2
diff -u -d -r1.18.2.1 -r1.18.2.2
--- mempool.h	28 Dec 2006 23:21:03 -0000	1.18.2.1
+++ mempool.h	18 Jan 2007 15:33:34 -0000	1.18.2.2
@@ -16,7 +16,7 @@
 
 typedef struct pool *pool_t;
 
-struct pool {
+struct pool_vfuncs {
 	const char *(*get_name)(pool_t pool);
 
 	void (*ref)(pool_t pool);
@@ -36,6 +36,10 @@
 	/* Returns the maximum amount of bytes that can be allocated with
 	   minimal trouble. If there's no such concept, always returns 0. */
 	size_t (*get_max_easy_alloc_size)(pool_t pool);
+};
+
+struct pool {
+	const struct pool_vfuncs *v;
 
 	unsigned int alloconly_pool:1;
 	unsigned int datastack_pool:1;
@@ -63,24 +67,25 @@
 size_t pool_get_exp_grown_size(pool_t pool, size_t old_size, size_t min_size);
 
 /* Pools should be used through these macros: */
-#define pool_get_name(pool) (pool)->get_name(pool)
-#define pool_ref(pool) (pool)->ref(pool)
-#define pool_unref(pool) (pool)->unref(&(pool))
+#define pool_get_name(pool) (pool)->v->get_name(pool)
+#define pool_ref(pool) (pool)->v->ref(pool)
+#define pool_unref(pool) (pool)->v->unref(&(pool))
 
 #define p_new(pool, type, count) \
 	((type *) p_malloc(pool, sizeof(type) * (count)))
 
-#define p_malloc(pool, size) (pool)->malloc(pool, size)
+#define p_malloc(pool, size) (pool)->v->malloc(pool, size)
 #define p_realloc(pool, mem, old_size, new_size) \
-	(pool)->realloc(pool, mem, old_size, new_size)
+	(pool)->v->realloc(pool, mem, old_size, new_size)
 #define p_free(pool, mem) \
 	STMT_START { \
-          (pool)->free(pool, mem); \
+          (pool)->v->free(pool, mem); \
           (mem) = NULL; \
 	} STMT_END
 
-#define p_clear(pool) (pool)->clear(pool)
+#define p_clear(pool) (pool)->v->clear(pool)
 
-#define p_get_max_easy_alloc_size(pool) (pool)->get_max_easy_alloc_size(pool)
+#define p_get_max_easy_alloc_size(pool) \
+	(pool)->v->get_max_easy_alloc_size(pool)
 
 #endif



More information about the dovecot-cvs mailing list