dovecot-2.2: lib: data-stack - reorder full current block code

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 28 13:54:28 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/76136a4ee1a3
changeset: 17644:76136a4ee1a3
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jul 28 16:45:33 2014 +0300
description:
lib: data-stack - reorder full current block code
Make the "enough space" and "block is full" branches in t_malloc_real
have the same code structure for parallelism. The 'block' variable is only
needed very locally, so shrink its scope, and avoid its use once it is
assigned to current_block, use that instead. Compacter readable expressions
have been favoured at the expense of longer lines (which will soon shrink).

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/data-stack.c |  23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)

diffs (61 lines):

diff -r 38c7901e9ff6 -r 76136a4ee1a3 src/lib/data-stack.c
--- a/src/lib/data-stack.c	Mon Jul 28 16:45:33 2014 +0300
+++ b/src/lib/data-stack.c	Mon Jul 28 16:45:33 2014 +0300
@@ -350,7 +350,6 @@
 
 static void *t_malloc_real(size_t size, bool permanent)
 {
-	struct stack_block *block;
 	void *ret;
 	size_t alloc_size;
 #ifdef DEBUG
@@ -386,14 +385,13 @@
 		ret = STACK_BLOCK_DATA(current_block) +
 			(current_block->size - current_block->left);
 
-		if (current_block->left - alloc_size <
-		    current_block->lowwater) {
-			current_block->lowwater =
-				current_block->left - alloc_size;
-		}
+		if (current_block->left - alloc_size < current_block->lowwater)
+			current_block->lowwater = current_block->left - alloc_size;
 		if (permanent)
 			current_block->left -= alloc_size;
 	} else {
+		struct stack_block *block;
+
 		/* current block is full, see if we can use the unused_block */
 		if (unused_block != NULL && unused_block->size >= alloc_size) {
 			block = unused_block;
@@ -406,23 +404,24 @@
 		}
 
 		block->left = block->size;
-		if (block->left - alloc_size < block->lowwater)
-			block->lowwater = block->left - alloc_size;
-		if (permanent)
-			block->left -= alloc_size;
 		block->next = NULL;
-
 		current_block->next = block;
 		current_block = block;
 
 		ret = STACK_BLOCK_DATA(current_block);
+
+		if (current_block->left - alloc_size < current_block->lowwater)
+			current_block->lowwater = current_block->left - alloc_size;
+		if (permanent)
+			current_block->left -= alloc_size;
+
 #ifdef DEBUG
 		if (warn && getenv("DEBUG_SILENT") == NULL) {
 			/* warn after allocation, so if i_warning() wants to
 			   allocate more memory we don't go to infinite loop */
 			i_warning("Growing data stack by %"PRIuSIZE_T" as "
 				  "'%s' reaches %llu bytes from %u allocations.",
-				  block->size,
+				  current_block->size,
 				  current_frame_block->marker[frame_pos],
 				  current_frame_block->alloc_bytes[frame_pos],
 				  current_frame_block->alloc_count[frame_pos]);


More information about the dovecot-cvs mailing list