[asterisk-commits] branch kpfleming/stringfields - r7762 in /team/kpfleming/stringfields: ./ inc...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 3 20:14:39 CST 2006


Author: kpfleming
Date: Tue Jan  3 20:14:39 2006
New Revision: 7762

URL: http://svn.digium.com/view/asterisk?rev=7762&view=rev
Log:
implement pool growth

Modified:
    team/kpfleming/stringfields/include/asterisk/stringfields.h
    team/kpfleming/stringfields/utils.c

Modified: team/kpfleming/stringfields/include/asterisk/stringfields.h
URL: http://svn.digium.com/view/asterisk/team/kpfleming/stringfields/include/asterisk/stringfields.h?rev=7762&r1=7761&r2=7762&view=diff
==============================================================================
--- team/kpfleming/stringfields/include/asterisk/stringfields.h (original)
+++ team/kpfleming/stringfields/include/asterisk/stringfields.h Tue Jan  3 20:14:39 2006
@@ -42,7 +42,7 @@
 
 int __ast_string_field_init(struct ast_string_field_pool *pool, size_t size);
 char *__ast_string_field_alloc_space(struct ast_string_field_pool *pool, size_t needed,
-				     ast_string_field *first_field, int num_fields);
+				     ast_string_field *fields, int num_fields);
 
 #define AST_STRING_FIELD_DEFAULT_POOL 1024
 

Modified: team/kpfleming/stringfields/utils.c
URL: http://svn.digium.com/view/asterisk/team/kpfleming/stringfields/utils.c?rev=7762&r1=7761&r2=7762&view=diff
==============================================================================
--- team/kpfleming/stringfields/utils.c (original)
+++ team/kpfleming/stringfields/utils.c Tue Jan  3 20:14:39 2006
@@ -937,15 +937,26 @@
 }
 
 char *__ast_string_field_alloc_space(struct ast_string_field_pool *pool, size_t needed,
-				     ast_string_field *first_field, int num_fields)
+				     ast_string_field *fields, int num_fields)
 {
 	char *result = NULL;
 
-	if (__builtin_expect(needed > pool->space , 0)) {
-		/* make more space */
+	if (__builtin_expect(needed > pool->space, 0)) {
+		int index;
+		char *new_base;
+
+		if (!(new_base = realloc(pool->base, pool->size * 2)))
+			return NULL;
+
+		for (index = 0; index < num_fields; index++)
+			fields[index] = new_base + (fields[index] - pool->base);
+		pool->base = new_base;
+		pool->space += pool->size;
+		pool->size *= 2;
 	}
 
 	result = pool->base + pool->used;
 	pool->used += needed;
+	pool->space -= needed;
 	return result;
 }



More information about the asterisk-commits mailing list