cvs: php4(PHP_4_0_7) /ext/standard php_smart_str.h

From: Date: Mon, 20 Aug 2001 15:30:33 +0000
Subject: cvs: php4(PHP_4_0_7) /ext/standard php_smart_str.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-6979@lists.php.net to get a copy of this message
sas Mon Aug 20 11:30:33 2001 EDT Modified files: (Branch: PHP_4_0_7) /php4/ext/standard php_smart_str.h Log: MFH Index: php4/ext/standard/php_smart_str.h diff -u php4/ext/standard/php_smart_str.h:1.11.2.1 php4/ext/standard/php_smart_str.h:1.11.2.2 --- php4/ext/standard/php_smart_str.h:1.11.2.1 Mon Aug 20 11:27:28 2001 +++ php4/ext/standard/php_smart_str.h Mon Aug 20 11:30:33 2001 @@ -78,32 +78,38 @@ static inline char *smart_str_print_long(char *buf, long num) { - /* TBFixed: think how to do it one-pass */ + char *p = buf, *end; + int n; long tmp; - char *p = buf; - int n = 0; - - if(num == 0) { - *p++ = '0'; - return p; - } if (num < 0) { num = -num; *p++ = '-'; } - for (tmp = num; tmp > 0; n++) { - tmp /= 10; + /* many numbers are < 10 */ + if (num < 10) { + *p++ = num + '0'; + return p; } - p += n; - while (num > 0) { - *(--p) = (num % 10) + '0'; + n = 1; + tmp = num; + + /* calculate the number of digits we need */ + do { + tmp /= 10; + n++; + } while (tmp >= 10); + + end = p += n; + + do { + *--p = (num % 10) + '0'; num /= 10; - } + } while (--n > 0); - return p+n; + return end; } static inline void smart_str_append_long_ex(smart_str *dest, long num, int type)

« previous php.cvs (#6979) next »