diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-07-02 18:58:04 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-07-02 18:58:04 +0300 |
commit | 9ea98d676b0b27e68a33d872928407750270503e (patch) | |
tree | 2e3fe10d196e4be5a0af2fc3378285ccc81e38a5 /ext/interbase/ibase_blobs.c | |
parent | 0fd2b4c030c8fc251954e8351dcc66dc10c0155c (diff) | |
download | php-git-9ea98d676b0b27e68a33d872928407750270503e.tar.gz |
Cleanup (avoid reallocations)
Diffstat (limited to 'ext/interbase/ibase_blobs.c')
-rw-r--r-- | ext/interbase/ibase_blobs.c | 22 |
1 files changed, 5 insertions, 17 deletions
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(); |