dovecot-2.2: lib: data-stack - pull common code out of if/else b...

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/87629dec23f1
changeset: 17645:87629dec23f1
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jul 28 16:45:33 2014 +0300
description:
lib: data-stack - pull common code out of if/else branches in t_malloc_real
Once the new block is set up nicely empty for use, it can be used exactly
like an old block that has enough space - so just merge the code paths.
(This changeset best viewed ignoring whitespace.)

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

diffstat:

 src/lib/data-stack.c |  45 ++++++++++++++++++---------------------------
 1 files changed, 18 insertions(+), 27 deletions(-)

diffs (67 lines):

diff -r 76136a4ee1a3 -r 87629dec23f1 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
@@ -380,16 +380,7 @@
 	/* used for t_try_realloc() */
 	current_frame_block->last_alloc_size[frame_pos] = alloc_size;
 
-	if (current_block->left >= alloc_size) {
-		/* enough space in current block, use it */
-		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 (permanent)
-			current_block->left -= alloc_size;
-	} else {
+	if (current_block->left < alloc_size) {
 		struct stack_block *block;
 
 		/* current block is full, see if we can use the unused_block */
@@ -407,28 +398,28 @@
 		block->next = NULL;
 		current_block->next = block;
 		current_block = block;
+	}
 
-		ret = STACK_BLOCK_DATA(current_block);
+	/* enough space in current block, use it */
+	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 (permanent)
-			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;
 
 #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.",
-				  current_block->size,
-				  current_frame_block->marker[frame_pos],
-				  current_frame_block->alloc_bytes[frame_pos],
-				  current_frame_block->alloc_count[frame_pos]);
-		}
-#endif
+	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.",
+			  current_block->size,
+			  current_frame_block->marker[frame_pos],
+			  current_frame_block->alloc_bytes[frame_pos],
+			  current_frame_block->alloc_count[frame_pos]);
 	}
-#ifdef DEBUG
 	memcpy(ret, &size, sizeof(size));
 	ret = PTR_OFFSET(ret, MEM_ALIGN(sizeof(size)));
 	/* make sure the sentry contains CLEAR_CHRs. it might not if we


More information about the dovecot-cvs mailing list