diff options
author | Nikita Popov <nikic@php.net> | 2014-05-01 08:55:59 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-05-01 09:08:30 +0200 |
commit | d820ea9f5e0895af054012116fcb9d65f40da56e (patch) | |
tree | e85d9b0d6e2c93bc178db37271db313fb549858e /Zend/zend_operators.c | |
parent | e0247de14701e38853a2a93b9763d60dd1df9bc8 (diff) | |
download | php-git-d820ea9f5e0895af054012116fcb9d65f40da56e.tar.gz |
Avoid superflous allocations in convert_to_string
Taken from zval_get_string.
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r-- | Zend/zend_operators.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index a72a75b1f3..5c79a98142 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -596,9 +596,6 @@ ZEND_API void _convert_to_cstring(zval *op ZEND_FILE_LINE_DC) /* {{{ */ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */ { - long lval; - double dval; - switch (Z_TYPE_P(op)) { case IS_NULL: case IS_FALSE: { @@ -612,32 +609,23 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */ case IS_STRING: break; case IS_RESOURCE: { - long tmp = Z_RES_HANDLE_P(op); - char *str; - int len; - - zval_ptr_dtor(op); - len = zend_spprintf(&str, 0, "Resource id #%ld", tmp); - ZVAL_NEW_STR(op, STR_INIT(str, len, 0)); - efree(str); + char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG]; + int len = snprintf(buf, sizeof(buf), "Resource id #%ld", Z_RES_HANDLE_P(op)); + ZVAL_NEW_STR(op, STR_INIT(buf, len, 0)); break; } case IS_LONG: { - char *str; - int len; - lval = Z_LVAL_P(op); - - len = zend_spprintf(&str, 0, "%ld", lval); - ZVAL_NEW_STR(op, STR_INIT(str, len, 0)); - efree(str); + char buf[MAX_LENGTH_OF_LONG + 1]; + int len = snprintf(buf, sizeof(buf), "%ld", Z_LVAL_P(op)); + ZVAL_NEW_STR(op, STR_INIT(buf, len, 0)); break; } case IS_DOUBLE: { char *str; int len; + double dval = Z_DVAL_P(op); TSRMLS_FETCH(); - dval = Z_DVAL_P(op); len = zend_spprintf(&str, 0, "%.*G", (int) EG(precision), dval); /* %G already handles removing trailing zeros from the fractional part, yay */ ZVAL_NEW_STR(op, STR_INIT(str, len, 0)); |