summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2004-07-19 07:19:50 +0000
committerAndi Gutmans <andi@php.net>2004-07-19 07:19:50 +0000
commit56f8195fe592e79d90c78fb015f39bffa7f39422 (patch)
tree6a1bf69bc9cd23fab98c4d3d6c12368b56d26079 /Zend/zend_operators.c
parent599ae4b1b53d46e10447dab8fb4faa2d0517370a (diff)
downloadphp-git-56f8195fe592e79d90c78fb015f39bffa7f39422.tar.gz
- Nuke empty_string. It is a reminanent from the time where RETURN_FALSE()
used to return "" and not bool(false). It's not worth keeping it because STR_FREE() and zval_dtor() always have to check for it and it slows down the general case. In addition, it seems that empty_string has been abused quite a lot, and was used not only for setting zval's but generally in PHP code instead of "", which wasn't the intention. Last but not least, nuking empty_string should improve stability as I doubt every place correctly checked if they are not mistakenly erealloc()'ing it or calling efree() on it. NOTE: Some code is probably broken. Each extension maintainer should check and see that my changes are OK. Also, I haven't had time to touch PECL yet. Will try and do it tomorrow.
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 96217df5b1..8ef15ba102 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -510,7 +510,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC)
switch (op->type) {
case IS_NULL:
- op->value.str.val = empty_string;
+ op->value.str.val = STR_EMPTY_ALLOC();
op->value.str.len = 0;
break;
case IS_STRING:
@@ -520,7 +520,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC)
op->value.str.val = estrndup_rel("1", 1);
op->value.str.len = 1;
} else {
- op->value.str.val = empty_string;
+ op->value.str.val = STR_EMPTY_ALLOC();
op->value.str.len = 0;
}
break;
@@ -1130,11 +1130,8 @@ ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2)
ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2)
{
int length = op1->value.str.len + op2->value.str.len;
- if (op1->value.str.val == empty_string) {
- result->value.str.val = (char *) emalloc(length+1);
- } else {
- result->value.str.val = (char *) erealloc(op1->value.str.val, length+1);
- }
+
+ result->value.str.val = (char *) erealloc(op1->value.str.val, length+1);
memcpy(result->value.str.val+op1->value.str.len, op2->value.str.val, op2->value.str.len);
result->value.str.val[length] = 0;
result->value.str.len = length;
@@ -1167,12 +1164,8 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
if (result==op1) { /* special case, perform operations on result */
uint res_len = op1->value.str.len + op2->value.str.len;
- if (result->value.str.len == 0) { /* handle empty_string */
- STR_FREE(result->value.str.val);
- result->value.str.val = emalloc(res_len+1);
- } else {
- result->value.str.val = erealloc(result->value.str.val, res_len+1);
- }
+ result->value.str.val = erealloc(result->value.str.val, res_len+1);
+
memcpy(result->value.str.val+result->value.str.len, op2->value.str.val, op2->value.str.len);
result->value.str.val[res_len]=0;
result->value.str.len = res_len;