Skip to content

Commit c6a6189

Browse files
committed
Simplify and comment
1 parent 41d2524 commit c6a6189

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

Zend/zend_operators.c

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ ZEND_API zend_result ZEND_FASTCALL shift_right_function(zval *result, zval *op1,
19401940
ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) /* {{{ */
19411941
{
19421942
zval *orig_op1 = op1;
1943-
zend_string *op1_string, *op2_string = NULL;
1943+
zend_string *op1_string, *op2_string;
19441944
bool free_op1_string = false;
19451945
bool free_op2_string = false;
19461946

@@ -1968,48 +1968,49 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
19681968
if (result == op1) {
19691969
if (UNEXPECTED(op1 == op2)) {
19701970
op2_string = op1_string;
1971+
goto has_op2_string;
19711972
}
19721973
}
19731974
}
19741975
} while (0);
19751976
do {
1976-
if (!op2_string) {
1977-
if (EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
1978-
op2_string = Z_STR_P(op2);
1979-
} else {
1980-
if (Z_ISREF_P(op2)) {
1981-
op2 = Z_REFVAL_P(op2);
1982-
if (Z_TYPE_P(op2) == IS_STRING) {
1983-
op2_string = Z_STR_P(op2);
1984-
break;
1985-
}
1986-
}
1987-
/* hold an additional reference because a userland function could free this */
1988-
if (!free_op1_string) {
1989-
op1_string = zend_string_copy(op1_string);
1990-
free_op1_string = true;
1977+
if (EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
1978+
op2_string = Z_STR_P(op2);
1979+
} else {
1980+
if (Z_ISREF_P(op2)) {
1981+
op2 = Z_REFVAL_P(op2);
1982+
if (Z_TYPE_P(op2) == IS_STRING) {
1983+
op2_string = Z_STR_P(op2);
1984+
break;
19911985
}
1992-
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_CONCAT);
1993-
op2_string = zval_get_string_func(op2);
1994-
if (UNEXPECTED(EG(exception))) {
1995-
zend_string_release(op1_string);
1996-
zend_string_release(op2_string);
1997-
if (orig_op1 != result) {
1998-
ZVAL_UNDEF(result);
1999-
}
2000-
return FAILURE;
1986+
}
1987+
/* hold an additional reference because a userland function could free this */
1988+
if (!free_op1_string) {
1989+
op1_string = zend_string_copy(op1_string);
1990+
free_op1_string = true;
1991+
}
1992+
ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_CONCAT);
1993+
op2_string = zval_get_string_func(op2);
1994+
if (UNEXPECTED(EG(exception))) {
1995+
zend_string_release(op1_string);
1996+
zend_string_release(op2_string);
1997+
if (orig_op1 != result) {
1998+
ZVAL_UNDEF(result);
20011999
}
2002-
free_op2_string = true;
2000+
return FAILURE;
20032001
}
2002+
free_op2_string = true;
20042003
}
20052004
} while (0);
20062005

2006+
has_op2_string:;
20072007
if (UNEXPECTED(ZSTR_LEN(op1_string) == 0)) {
20082008
if (EXPECTED(free_op2_string || result != op2)) {
20092009
if (result == orig_op1) {
20102010
i_zval_ptr_dtor(result);
20112011
}
20122012
if (free_op2_string) {
2013+
/* transfer ownership of op2_string */
20132014
ZVAL_STR(result, op2_string);
20142015
free_op2_string = false;
20152016
} else {
@@ -2022,6 +2023,7 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
20222023
i_zval_ptr_dtor(result);
20232024
}
20242025
if (free_op1_string) {
2026+
/* transfer ownership of op1_string */
20252027
ZVAL_STR(result, op1_string);
20262028
free_op1_string = false;
20272029
} else {
@@ -2047,16 +2049,19 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
20472049

20482050
if (result == op1) {
20492051
if (free_op1_string) {
2052+
/* op1_string will be used as the result, so we should not free it */
20502053
i_zval_ptr_dtor(result);
20512054
free_op1_string = false;
20522055
}
20532056
/* special case, perform operations on result */
20542057
result_str = zend_string_extend(op1_string, result_len, 0);
20552058
/* account for the case where result_str == op1_string == op2_string and the realloc is done */
20562059
if (op1_string == op2_string) {
2057-
if (free_op2_string) zend_string_release(op2_string);
2060+
if (free_op2_string) {
2061+
zend_string_release(op2_string);
2062+
free_op2_string = false;
2063+
}
20582064
op2_string = result_str;
2059-
free_op2_string = false;
20602065
}
20612066
} else {
20622067
result_str = zend_string_alloc(result_len, 0);

0 commit comments

Comments
 (0)