Browse Source

Cleanup (avoid reallocations)

pull/1383/head
Dmitry Stogov 11 years ago
parent
commit
9ea98d676b
  1. 22
      ext/interbase/ibase_blobs.c
  2. 8
      ext/interbase/ibase_query.c
  3. 2
      ext/interbase/php_ibase_includes.h

22
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();

8
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:

2
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);

Loading…
Cancel
Save