dovecot-2.2: lib: data-stack - helper for last alloc ends at blo...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 28 13:54:29 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/5567eedee0c2
changeset: 17647:5567eedee0c2
user: Phil Carmody <phil at dovecot.fi>
date: Mon Jul 28 16:45:33 2014 +0300
description:
lib: data-stack - helper for last alloc ends at block.data+(size-left)
Less to read, and less noisy.
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/lib/data-stack.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diffs (56 lines):
diff -r 90a8729d81c8 -r 5567eedee0c2 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
@@ -91,6 +91,12 @@
unsigned char data[512];
} outofmem_area;
+static inline
+unsigned char *data_stack_after_last_alloc(struct stack_block *block)
+{
+ return STACK_BLOCK_DATA(block) + (block->size - block->left);
+}
+
static void data_stack_last_buffer_reset(bool preserve_data ATTR_UNUSED)
{
if (last_buffer_block != NULL) {
@@ -98,8 +104,7 @@
unsigned char *last_alloc_end, *p;
unsigned int i;
- last_alloc_end = STACK_BLOCK_DATA(current_block) +
- (current_block->size - current_block->left);
+ last_alloc_end = data_stack_after_last_alloc(current_block);
p = last_alloc_end + MEM_ALIGN(sizeof(size_t)) + MEM_ALIGN(last_buffer_size);
#endif
@@ -402,8 +407,7 @@
}
/* enough space in current block, use it */
- ret = STACK_BLOCK_DATA(current_block) +
- (current_block->size - current_block->left);
+ ret = data_stack_after_last_alloc(current_block);
if (current_block->left - alloc_size < current_block->lowwater)
current_block->lowwater = current_block->left - alloc_size;
@@ -451,6 +455,7 @@
bool t_try_realloc(void *mem, size_t size)
{
size_t last_alloc_size;
+ unsigned char *after_last_alloc;
if (unlikely(size == 0 || size > SSIZE_T_MAX))
i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
@@ -459,9 +464,8 @@
last_alloc_size = current_frame_block->last_alloc_size[frame_pos];
/* see if we're trying to grow the memory we allocated last */
- if (STACK_BLOCK_DATA(current_block) +
- (current_block->size - current_block->left -
- last_alloc_size) == mem) {
+ after_last_alloc = data_stack_after_last_alloc(current_block);
+ if (after_last_alloc - last_alloc_size == mem) {
/* yeah, see if we have space to grow */
size = MEM_ALIGN(size);
if (current_block->left >= size - last_alloc_size) {
More information about the dovecot-cvs
mailing list