summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2001-08-20 15:27:45 +0000
committerSascha Schumann <sas@php.net>2001-08-20 15:27:45 +0000
commit01672af8f03ff7a301cf95b2903de42220805dcb (patch)
treec9e58c35eb86452d643ff8014687148e5d66aa37
parent902100a6920dd49c681d90b41f0a9507389cab65 (diff)
downloadphp-git-01672af8f03ff7a301cf95b2903de42220805dcb.tar.gz
Improved fix
-rw-r--r--ext/standard/php_smart_str.h36
1 files changed, 21 insertions, 15 deletions
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
index 0edaa4a9d4..ea34d792a1 100644
--- a/ext/standard/php_smart_str.h
+++ b/ext/standard/php_smart_str.h
@@ -78,32 +78,38 @@ static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t
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)