From: Dmitry Stogov Date: Thu, 2 Jul 2015 15:58:04 +0000 (+0300) Subject: Cleanup (avoid reallocations) X-Git-Tag: php-7.1.0alpha3~25^2~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ea98d676b0b27e68a33d872928407750270503e;p=php Cleanup (avoid reallocations) --- diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c index 7008026ff4..ba384f8cd2 100644 --- a/ext/interbase/ibase_blobs.c +++ b/ext/interbase/ibase_blobs.c @@ -70,18 +70,15 @@ int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd) /* {{{ */ } /* }}} */ -char *_php_ibase_quad_to_string(ISC_QUAD const qd) /* {{{ */ +zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd) /* {{{ */ { - char *result; - /* shortcut for most common case */ if (sizeof(ISC_QUAD) == sizeof(ISC_UINT64)) { - spprintf(&result, BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd); + return strpprintf(BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd); } else { ISC_UINT64 res = ((ISC_UINT64) qd.gds_quad_high << 0x20) | qd.gds_quad_low; - spprintf(&result, BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, res); + return strpprintf(BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, res); } - return result; } /* }}} */ @@ -347,7 +344,6 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{ { zval *blob_arg; ibase_blob *ib_blob; - char *s; RESET_ERRMSG; @@ -367,10 +363,7 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{ } ib_blob->bl_handle = NULL; - s = _php_ibase_quad_to_string(ib_blob->bl_qd); - // TODO: avoid double reallocation??? - RETVAL_STRINGL(s, BLOB_ID_LEN); - efree(s); + RETVAL_NEW_STR(_php_ibase_quad_to_string(ib_blob->bl_qd)); } else { /* discard created blob */ if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) { _php_ibase_error(); @@ -550,7 +543,6 @@ PHP_FUNCTION(ibase_blob_import) ibase_trans *trans = NULL; char bl_data[IBASE_BLOB_SEG]; php_stream *stream; - char *s; RESET_ERRMSG; @@ -578,11 +570,7 @@ PHP_FUNCTION(ibase_blob_import) if (isc_close_blob(IB_STATUS, &ib_blob.bl_handle)) { break; } - s = _php_ibase_quad_to_string(ib_blob.bl_qd); - // TODO: avoid double reallocation??? - RETVAL_STRINGL(s, BLOB_ID_LEN); - efree(s); - return; + RETURN_NEW_STR(_php_ibase_quad_to_string(ib_blob.bl_qd)); } while (0); _php_ibase_error(); diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index 46b3650b01..43fa760833 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -1599,9 +1599,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) } else { /* blob id only */ char *s; ISC_QUAD bl_qd = *(ISC_QUAD *) var->sqldata; - s = _php_ibase_quad_to_string(bl_qd); - ZVAL_STRINGL(&result, s, BLOB_ID_LEN); - efree(s); + ZVAL_NEW_STR(&result, _php_ibase_quad_to_string(bl_qd)); } break; case SQL_ARRAY: @@ -1626,10 +1624,8 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) efree(ar_data); } else { /* blob id only */ - char *s; ISC_QUAD ar_qd = *(ISC_QUAD *) var->sqldata; - s = _php_ibase_quad_to_string(ar_qd); - ZVAL_STRINGL(&result, s, BLOB_ID_LEN); + ZVAL_NEW_STR(&result, _php_ibase_quad_to_string(ar_qd)); } break; _php_ibase_fetch_error: diff --git a/ext/interbase/php_ibase_includes.h b/ext/interbase/php_ibase_includes.h index ab63a14842..03fa6e3cf0 100644 --- a/ext/interbase/php_ibase_includes.h +++ b/ext/interbase/php_ibase_includes.h @@ -180,7 +180,7 @@ void php_ibase_query_minit(INIT_FUNC_ARGS); /* provided by ibase_blobs.c */ void php_ibase_blobs_minit(INIT_FUNC_ARGS); int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd); -char *_php_ibase_quad_to_string(ISC_QUAD const qd); +zend_string *_php_ibase_quad_to_string(ISC_QUAD const qd); int _php_ibase_blob_get(zval *return_value, ibase_blob *ib_blob, unsigned long max_len); int _php_ibase_blob_add(zval *string_arg, ibase_blob *ib_blob);