[asterisk-commits] russell: branch russell/ast_verbose_threadstorage r38488 - /team/russell/ast_...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Jul 29 11:39:13 MST 2006


Author: russell
Date: Sat Jul 29 13:39:13 2006
New Revision: 38488

URL: http://svn.digium.com/view/asterisk?rev=38488&view=rev
Log:
Modify the dynamic string growth algorithm such that instead of always doubling
the size of the string buffer when it is not big enough, grow by exactly how
much is needed, since that information is provided by the return value of 
vsnprintf.  This also eliminates unneeded repeated calls to this function by
making it a maximum of 2 times - once where it finds out the buffer isn't big
enough and increases it, and another that is successful.

Modified:
    team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h

Modified: team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h
URL: http://svn.digium.com/view/asterisk/team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h?rev=38488&r1=38487&r2=38488&view=diff
==============================================================================
--- team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h (original)
+++ team/russell/ast_verbose_threadstorage/include/asterisk/threadstorage.h Sat Jul 29 13:39:13 2006
@@ -271,10 +271,13 @@
 
 	res = vsnprintf((*buf)->str, (*buf)->len, fmt, ap);
 	
-	if (res >= (*buf)->len && (max_len ? ((*buf)->len <= (max_len / 2)) : 1)) {
-		if (!(*buf = ast_realloc(*buf, ((*buf)->len * 2) + sizeof(*(*buf)))))
+	if ((res + 1) > (*buf)->len && (max_len ? ((*buf)->len < max_len) : 1)) {
+		if (max_len)
+			(*buf)->len = ((res + 1) < max_len) ? (res + 1) : max_len;
+		else
+			(*buf)->len = res + 1;
+		if (!(*buf = ast_realloc(*buf, (*buf)->len + sizeof(*(*buf)))))
 			return AST_DYNSTR_BUILD_FAILED;
-		(*buf)->len *= 2;
 		if (ts)
 			pthread_setspecific(ts->key, *buf);
 		return AST_DYNSTR_BUILD_RETRY;



More information about the asterisk-commits mailing list