diff options
author | Nikita Popov <nikic@php.net> | 2014-05-23 13:10:50 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-05-23 13:10:50 +0200 |
commit | 1d8c499b5152a9e52729ce8e6b2a0feee0192a43 (patch) | |
tree | c9513d51d4a68feea86f94b760fbd2e20990e997 /ext/standard/php_smart_str.h | |
parent | 47785868968d5e30a6bbaa32797ea251bb42bbd5 (diff) | |
download | php-git-1d8c499b5152a9e52729ce8e6b2a0feee0192a43.tar.gz |
Optimize int to string conversion
Probably platform depedentant, but for me snprintf is terribly
slow.
The code for the long printing is taken from the smart string
API.
Diffstat (limited to 'ext/standard/php_smart_str.h')
-rw-r--r-- | ext/standard/php_smart_str.h | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h index 81b92d7a80..e10a711435 100644 --- a/ext/standard/php_smart_str.h +++ b/ext/standard/php_smart_str.h @@ -123,31 +123,6 @@ __dest->s->len = __nl; \ } while (0) -/* input: buf points to the END of the buffer */ -#define smart_str_print_unsigned4(buf, num, vartype, result) do { \ - char *__p = (buf); \ - vartype __num = (num); \ - *__p = '\0'; \ - do { \ - *--__p = (char) (__num % 10) + '0'; \ - __num /= 10; \ - } while (__num > 0); \ - result = __p; \ -} while (0) - -/* buf points to the END of the buffer */ -#define smart_str_print_long4(buf, num, vartype, result) do { \ - if (num < 0) { \ - /* this might cause problems when dealing with LONG_MIN \ - and machines which don't support long long. Works \ - flawlessly on 32bit x86 */ \ - smart_str_print_unsigned4((buf), -(num), vartype, (result));\ - *--(result) = '-'; \ - } else { \ - smart_str_print_unsigned4((buf), (num), vartype, (result)); \ - } \ -} while (0) - /* * these could be replaced using a braced-group inside an expression * for GCC compatible compilers, e.g. @@ -157,20 +132,20 @@ static inline char *smart_str_print_long(char *buf, long num) { char *r; - smart_str_print_long4(buf, num, unsigned long, r); + _zend_print_signed_to_buf(buf, num, unsigned long, r); return r; } static inline char *smart_str_print_unsigned(char *buf, long num) { char *r; - smart_str_print_unsigned4(buf, num, unsigned long, r); + _zend_print_unsigned_to_buf(buf, num, unsigned long, r); return r; } #define smart_str_append_generic_ex(dest, num, type, vartype, func) do { \ char __b[32]; \ char *__t; \ - smart_str_print##func##4 (__b + sizeof(__b) - 1, (num), vartype, __t); \ + _zend_print##func##_to_buf (__b + sizeof(__b) - 1, (num), vartype, __t); \ smart_str_appendl_ex((dest), __t, __b + sizeof(__b) - 1 - __t, (type)); \ } while (0) @@ -178,10 +153,10 @@ static inline char *smart_str_print_unsigned(char *buf, long num) { smart_str_append_generic_ex((dest), (num), (type), unsigned long, _unsigned) #define smart_str_append_long_ex(dest, num, type) \ - smart_str_append_generic_ex((dest), (num), (type), unsigned long, _long) + smart_str_append_generic_ex((dest), (num), (type), unsigned long, _signed) #define smart_str_append_off_t_ex(dest, num, type) \ - smart_str_append_generic_ex((dest), (num), (type), off_t, _long) + smart_str_append_generic_ex((dest), (num), (type), off_t, _signed) #define smart_str_append_ex(dest, src, what) \ smart_str_appendl_ex((dest), ((smart_str *)(src))->s->val, \ |