com php-src: Cleanup (avoid reallocations): ext/interbase/ibase _blobs.c ext/interbase/ibase_query.c ext/interbase/ php_ibase_includes.h
| From: | Dmitry Stogov | Date: | Thu, 02 Jul 2015 15:58:04 +0000 |
| Subject: | com php-src: Cleanup (avoid reallocations): ext/interbase/ibase _blobs.c ext/interbase/ibase_query.c ext/interbase/ php_ibase_includes.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87706@lists.php.net to get a copy of this message | ||
Commit: 9ea98d676b0b27e68a33d872928407750270503e
Author: Dmitry Stogov <dmitry@zend.com> Thu, 2 Jul 2015 18:58:04 +0300
Parents: 0fd2b4c030c8fc251954e8351dcc66dc10c0155c
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9ea98d676b0b27e68a33d872928407750270503e
Log:
Cleanup (avoid reallocations)
Changed paths:
M ext/interbase/ibase_blobs.c
M ext/interbase/ibase_query.c
M ext/interbase/php_ibase_includes.h
Diff:
diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c
index 7008026...ba384f8 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 46b3650..43fa760 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 ab63a14..03fa6e3 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);