Skip to content

Commit 3bc8a95

Browse files
committed
Fixed useless or duplicated IS_INTERNED() checks
1 parent 3ec7c28 commit 3bc8a95

32 files changed

+79
-76
lines changed

Zend/zend_API.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1144,9 +1144,8 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties TSRMLS_DC)
11441144
if (key) {
11451145
zval member;
11461146

1147-
ZVAL_STR(&member, zend_string_copy(key));
1147+
ZVAL_STR(&member, key);
11481148
obj_ht->write_property(obj, &member, value, NULL TSRMLS_CC);
1149-
zval_ptr_dtor(&member);
11501149
}
11511150
} ZEND_HASH_FOREACH_END();
11521151
EG(scope) = old_scope;

Zend/zend_closures.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp TSRMLS_
376376
arg_info->pass_by_reference ? "&" : "",
377377
i + 1);
378378
}
379-
ZVAL_STR(&info, zend_strpprintf(0, "%s", i >= required ? "<optional>" : "<required>"));
379+
ZVAL_NEW_STR(&info, zend_strpprintf(0, "%s", i >= required ? "<optional>" : "<required>"));
380380
zend_hash_update(Z_ARRVAL(val), name, &info);
381381
zend_string_release(name);
382382
arg_info++;

Zend/zend_compile.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int li
315315
if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
316316
zend_string_hash_val(Z_STR_P(zv));
317317
Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv) TSRMLS_CC);
318-
if (IS_INTERNED(Z_STR_P(zv))) {
318+
if (!Z_REFCOUNTED_P(zv)) {
319319
Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
320320
}
321321
}
@@ -6559,7 +6559,7 @@ static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast TSRMLS_DC)
65596559
case T_METHOD_C:
65606560
if (ce) {
65616561
if (op_array && op_array->function_name) {
6562-
ZVAL_STR(zv, zend_concat3(ce->name->val, ce->name->len, "::", 2,
6562+
ZVAL_NEW_STR(zv, zend_concat3(ce->name->val, ce->name->len, "::", 2,
65636563
op_array->function_name->val, op_array->function_name->len));
65646564
} else {
65656565
ZVAL_STR(zv, zend_string_copy(ce->name));
@@ -7415,7 +7415,7 @@ void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
74157415
class_name->val, class_name->len, "::", 2, const_name->val, const_name->len);
74167416

74177417
Z_TYPE_INFO(result) = IS_CONSTANT_EX;
7418-
if (IS_INTERNED(Z_STR(result))) {
7418+
if (!Z_REFCOUNTED(result)) {
74197419
Z_TYPE_FLAGS(result) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
74207420
}
74217421
Z_CONST_FLAGS(result) = fetch_type;

Zend/zend_execute.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ static void zend_assign_to_string_offset(zval *str, zend_long offset, zval *valu
766766
Z_TYPE_INFO_P(str) = IS_STRING_EX;
767767
memset(Z_STRVAL_P(str) + old_len, ' ', offset - old_len);
768768
Z_STRVAL_P(str)[offset+1] = 0;
769-
} else if (IS_INTERNED(Z_STR_P(str))) {
769+
} else if (!Z_REFCOUNTED_P(str)) {
770770
Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
771771
Z_TYPE_INFO_P(str) = IS_STRING_EX;
772772
}
@@ -1076,8 +1076,13 @@ static zend_always_inline zval *zend_fetch_dimension_address(zval *result, zval
10761076
}
10771077

10781078
if (allow_str_offset) {
1079-
SEPARATE_STRING(container);
1080-
if (!IS_INTERNED(Z_STR_P(container))) zend_string_addref(Z_STR_P(container));
1079+
if (Z_REFCOUNTED_P(container)) {
1080+
if (Z_REFCOUNT_P(container) > 1) {
1081+
Z_DELREF_P(container);
1082+
zval_copy_ctor_func(container);
1083+
}
1084+
Z_ADDREF_P(container);
1085+
}
10811086
ZVAL_LONG(result, offset);
10821087
return container; /* assignment to string offset */
10831088
} else {

Zend/zend_execute_API.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ ZEND_API int zval_update_constant_ex(zval *p, zend_bool inline_change, zend_clas
580580
if (!inline_change) {
581581
ZVAL_STRINGL(p, actual, actual_len);
582582
} else {
583-
Z_TYPE_INFO_P(p) = IS_INTERNED(Z_STR_P(p)) ?
584-
IS_INTERNED_STRING_EX : IS_STRING_EX;
583+
Z_TYPE_INFO_P(p) = Z_REFCOUNTED_P(p) ?
584+
IS_STRING_EX : IS_INTERNED_STRING_EX;
585585
if (save && save->val != actual) {
586586
zend_string_release(save);
587587
}

Zend/zend_operators.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{
15411541
zend_error_noreturn(E_ERROR, "String size overflow");
15421542
}
15431543

1544-
if (result == op1 && !IS_INTERNED(Z_STR_P(result))) {
1544+
if (result == op1 && Z_REFCOUNTED_P(result)) {
15451545
/* special case, perform operations on result */
15461546
result_str = zend_string_realloc(Z_STR_P(result), result_len, 0);
15471547
} else {
@@ -2019,7 +2019,7 @@ static void increment_string(zval *str) /* {{{ */
20192019
return;
20202020
}
20212021

2022-
if (IS_INTERNED(Z_STR_P(str))) {
2022+
if (!Z_REFCOUNTED_P(str)) {
20232023
Z_STR_P(str) = zend_string_init(Z_STRVAL_P(str), Z_STRLEN_P(str), 0);
20242024
Z_TYPE_INFO_P(str) = IS_STRING_EX;
20252025
} else if (Z_REFCOUNT_P(str) > 1) {

Zend/zend_string.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static zend_always_inline zend_string *zend_string_init(const char *str, size_t
140140
static zend_always_inline zend_string *zend_string_copy(zend_string *s)
141141
{
142142
if (!IS_INTERNED(s)) {
143-
zend_string_addref(s);
143+
GC_REFCOUNT(s)++;
144144
}
145145
return s;
146146
}
@@ -161,14 +161,14 @@ static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_
161161
if (IS_INTERNED(s)) {
162162
ret = zend_string_alloc(len, persistent);
163163
memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
164-
} else if (EXPECTED(zend_string_refcount(s) == 1)) {
164+
} else if (EXPECTED(GC_REFCOUNT(s) == 1)) {
165165
ret = (zend_string *)perealloc(s, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + len + 1), persistent);
166166
ret->len = len;
167167
zend_string_forget_hash_val(ret);
168168
} else {
169169
ret = zend_string_alloc(len, persistent);
170170
memcpy(ret->val, s->val, (len > s->len ? s->len : len) + 1);
171-
zend_string_delref(s);
171+
GC_REFCOUNT(s)--;
172172
}
173173
return ret;
174174
}
@@ -180,30 +180,30 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
180180
if (IS_INTERNED(s)) {
181181
ret = zend_string_safe_alloc(n, m, l, persistent);
182182
memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
183-
} else if (zend_string_refcount(s) == 1) {
183+
} else if (GC_REFCOUNT(s) == 1) {
184184
ret = (zend_string *)safe_perealloc(s, n, m, ZEND_MM_ALIGNED_SIZE(_STR_HEADER_SIZE + l + 1), persistent);
185185
ret->len = (n * m) + l;
186186
zend_string_forget_hash_val(ret);
187187
} else {
188188
ret = zend_string_safe_alloc(n, m, l, persistent);
189189
memcpy(ret->val, s->val, ((n * m) + l > (size_t)s->len ? (size_t)s->len : ((n * m) + l)) + 1);
190-
zend_string_delref(s);
190+
GC_REFCOUNT(s)--;
191191
}
192192
return ret;
193193
}
194194

195195
static zend_always_inline void zend_string_free(zend_string *s)
196196
{
197197
if (!IS_INTERNED(s)) {
198-
ZEND_ASSERT(zend_string_refcount(s) <= 1);
198+
ZEND_ASSERT(GC_REFCOUNT(s) <= 1);
199199
pefree(s, GC_FLAGS(s) & IS_STR_PERSISTENT);
200200
}
201201
}
202202

203203
static zend_always_inline void zend_string_release(zend_string *s)
204204
{
205205
if (!IS_INTERNED(s)) {
206-
if (zend_string_delref(s) == 0) {
206+
if (--GC_REFCOUNT(s) == 0) {
207207
pefree(s, GC_FLAGS(s) & IS_STR_PERSISTENT);
208208
}
209209
}

ext/date/php_date.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ static HashTable *date_object_get_properties(zval *object TSRMLS_DC) /* {{{ */
22202220
abs(utc_offset / 60),
22212221
abs((utc_offset % 60)));
22222222

2223-
ZVAL_STR(&zv, tmpstr);
2223+
ZVAL_NEW_STR(&zv, tmpstr);
22242224
}
22252225
break;
22262226
case TIMELIB_ZONETYPE_ABBR:
@@ -2312,7 +2312,7 @@ static HashTable *date_object_get_properties_timezone(zval *object TSRMLS_DC) /*
23122312
abs(tzobj->tzi.utc_offset / 60),
23132313
abs((tzobj->tzi.utc_offset % 60)));
23142314

2315-
ZVAL_STR(&zv, tmpstr);
2315+
ZVAL_NEW_STR(&zv, tmpstr);
23162316
}
23172317
break;
23182318
case TIMELIB_ZONETYPE_ABBR:

ext/dom/documenttype.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int dom_documenttype_internal_subset_read(dom_object *obj, zval *retval TSRMLS_D
204204

205205
if (ret_buf.s) {
206206
smart_str_0(&ret_buf);
207-
ZVAL_STR(retval, ret_buf.s);
207+
ZVAL_NEW_STR(retval, ret_buf.s);
208208
return SUCCESS;
209209
}
210210
}

ext/fileinfo/libmagic/softmagic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ convert_libmagic_pattern(zval *pattern, char *val, int len, int options)
19131913
t->val[j]='\0';
19141914
t->len = j;
19151915

1916-
ZVAL_STR(pattern, t);
1916+
ZVAL_NEW_STR(pattern, t);
19171917
}
19181918

19191919
private int

ext/filter/sanitizing_filters.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void php_filter_encode_html(zval *value, const unsigned char *chars)
5252

5353
smart_str_0(&str);
5454
zval_ptr_dtor(value);
55-
ZVAL_STR(value, str.s);
55+
ZVAL_NEW_STR(value, str.s);
5656
}
5757

5858
static const unsigned char hexchars[] = "0123456789ABCDEF";
@@ -105,7 +105,7 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const
105105
*p = '\0';
106106
str->len = p - (unsigned char *)str->val;
107107
zval_ptr_dtor(value);
108-
ZVAL_STR(value, str);
108+
ZVAL_NEW_STR(value, str);
109109
}
110110

111111
static void php_filter_strip(zval *value, zend_long flags)
@@ -135,7 +135,7 @@ static void php_filter_strip(zval *value, zend_long flags)
135135
buf->val[c] = '\0';
136136
buf->len = c;
137137
zval_ptr_dtor(value);
138-
ZVAL_STR(value, buf);
138+
ZVAL_NEW_STR(value, buf);
139139
}
140140
/* }}} */
141141

@@ -174,7 +174,7 @@ static void filter_map_apply(zval *value, filter_map *map)
174174
buf->val[c] = '\0';
175175
buf->len = c;
176176
zval_ptr_dtor(value);
177-
ZVAL_STR(value, buf);
177+
ZVAL_NEW_STR(value, buf);
178178
}
179179
/* }}} */
180180

@@ -184,7 +184,7 @@ void php_filter_string(PHP_INPUT_FILTER_PARAM_DECL)
184184
size_t new_len;
185185
unsigned char enc[256] = {0};
186186

187-
if (IS_INTERNED(Z_STR_P(value))) {
187+
if (!Z_REFCOUNTED_P(value)) {
188188
ZVAL_STRINGL(value, Z_STRVAL_P(value), Z_STRLEN_P(value));
189189
}
190190

ext/gmp/gmp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static void gmp_strval(zval *result, mpz_t gmpnum, zend_long base) /* {{{ */
790790
str->val[str->len] = '\0';
791791
}
792792

793-
ZVAL_STR(result, str);
793+
ZVAL_NEW_STR(result, str);
794794
}
795795
/* }}} */
796796

ext/intl/idn/idn.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
184184
add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, return_value);
185185
} else {
186186
zval zv;
187-
ZVAL_STR(&zv, buffer);
187+
ZVAL_NEW_STR(&zv, buffer);
188188
buffer_used = 1;
189189
add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, &zv);
190190
}

ext/json/json.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ static PHP_FUNCTION(json_encode)
789789
ZVAL_FALSE(return_value);
790790
} else {
791791
smart_str_0(&buf); /* copy? */
792-
ZVAL_STR(return_value, buf.s);
792+
ZVAL_NEW_STR(return_value, buf.s);
793793
}
794794
}
795795
/* }}} */

ext/mysqli/mysqli_prop.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static zval *__func(mysqli_object *obj, zval *retval TSRMLS_DC) \
8484
if (l < ZEND_LONG_MAX) {\
8585
ZVAL_LONG(retval, (zend_long) l);\
8686
} else { \
87-
ZVAL_STR(retval, strpprintf(0, __ret_type_sprint_mod, l)); \
87+
ZVAL_NEW_STR(retval, strpprintf(0, __ret_type_sprint_mod, l)); \
8888
} \
8989
}\
9090
return retval;\
@@ -170,7 +170,7 @@ static zval *link_affected_rows_read(mysqli_object *obj, zval *retval TSRMLS_DC)
170170
if (rc < ZEND_LONG_MAX) {
171171
ZVAL_LONG(retval, (zend_long) rc);
172172
} else {
173-
ZVAL_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
173+
ZVAL_NEW_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
174174
}
175175
}
176176
return retval;
@@ -357,7 +357,7 @@ static zval *stmt_affected_rows_read(mysqli_object *obj, zval *retval TSRMLS_DC)
357357
if (rc < ZEND_LONG_MAX) {
358358
ZVAL_LONG(retval, (zend_long) rc);
359359
} else {
360-
ZVAL_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
360+
ZVAL_NEW_STR(retval, strpprintf(0, MYSQLI_LLU_SPEC, rc));
361361
}
362362
}
363363
return retval;

ext/mysqlnd/mysqlnd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * cons
24962496
DBG_INF_FMT("Adding [%s][%s]", key, value);
24972497
{
24982498
zval attrz;
2499-
ZVAL_STR(&attrz, zend_string_init(value, strlen(value), 1));
2499+
ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 1));
25002500
zend_hash_str_update(conn->options->connect_attr, key, strlen(key), &attrz);
25012501
}
25022502
break;

ext/opcache/Optimizer/block_pass.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
911911
}
912912
old_len = Z_STRLEN(ZEND_OP1_LITERAL(last_op));
913913
l = old_len + Z_STRLEN(ZEND_OP1_LITERAL(opline));
914-
if (IS_INTERNED(Z_STR(ZEND_OP1_LITERAL(last_op)))) {
914+
if (!Z_REFCOUNTED(ZEND_OP1_LITERAL(last_op))) {
915915
zend_string *tmp = zend_string_alloc(l, 0);
916916
memcpy(tmp->val, Z_STRVAL(ZEND_OP1_LITERAL(last_op)), old_len);
917917
Z_STR(ZEND_OP1_LITERAL(last_op)) = tmp;
@@ -923,7 +923,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
923923
Z_STRVAL(ZEND_OP1_LITERAL(last_op))[l] = '\0';
924924
zval_dtor(&ZEND_OP1_LITERAL(opline));
925925
Z_STR(ZEND_OP1_LITERAL(opline)) = zend_new_interned_string(Z_STR(ZEND_OP1_LITERAL(last_op)) TSRMLS_CC);
926-
if (IS_INTERNED(Z_STR(ZEND_OP1_LITERAL(opline)))) {
926+
if (!Z_REFCOUNTED(ZEND_OP1_LITERAL(opline))) {
927927
Z_TYPE_FLAGS(ZEND_OP1_LITERAL(opline)) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
928928
}
929929
ZVAL_NULL(&ZEND_OP1_LITERAL(last_op));
@@ -955,7 +955,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
955955
COPY_NODE(opline->op1, src->op1);
956956
old_len = Z_STRLEN(ZEND_OP2_LITERAL(src));
957957
l = old_len + Z_STRLEN(ZEND_OP2_LITERAL(opline));
958-
if (IS_INTERNED(Z_STR(ZEND_OP2_LITERAL(src)))) {
958+
if (!Z_REFCOUNTED(ZEND_OP2_LITERAL(src))) {
959959
zend_string *tmp = zend_string_alloc(l, 0);
960960
memcpy(tmp->val, Z_STRVAL(ZEND_OP2_LITERAL(src)), old_len);
961961
Z_STR(ZEND_OP2_LITERAL(last_op)) = tmp;
@@ -967,7 +967,7 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
967967
Z_STRVAL(ZEND_OP2_LITERAL(src))[l] = '\0';
968968
zend_string_release(Z_STR(ZEND_OP2_LITERAL(opline)));
969969
Z_STR(ZEND_OP2_LITERAL(opline)) = zend_new_interned_string(Z_STR(ZEND_OP2_LITERAL(src)) TSRMLS_CC);
970-
if (IS_INTERNED(Z_STR(ZEND_OP2_LITERAL(opline)))) {
970+
if (!Z_REFCOUNTED(ZEND_OP2_LITERAL(opline))) {
971971
Z_TYPE_FLAGS(ZEND_OP2_LITERAL(opline)) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
972972
}
973973
ZVAL_NULL(&ZEND_OP2_LITERAL(src));

ext/opcache/zend_accelerator_util_funcs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ static inline zend_string *zend_clone_str(zend_string *str TSRMLS_DC)
232232

233233
if (IS_INTERNED(str)) {
234234
ret = str;
235-
} else if (zend_string_refcount(str) <= 1 || (ret = accel_xlat_get(str)) == NULL) {
235+
} else if (GC_REFCOUNT(str) <= 1 || (ret = accel_xlat_get(str)) == NULL) {
236236
ret = zend_string_dup(str, 0);
237237
GC_FLAGS(ret) = GC_FLAGS(str);
238-
if (zend_string_refcount(str) > 1) {
238+
if (GC_REFCOUNT(str) > 1) {
239239
accel_xlat_set(str, ret);
240240
}
241241
} else {
242-
zend_string_addref(ret);
242+
GC_REFCOUNT(ret)++;
243243
}
244244
return ret;
245245
}

ext/opcache/zend_persist_calc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static uint zend_persist_zval_calc(zval *z TSRMLS_DC)
120120
case IS_CONSTANT:
121121
flags = Z_GC_FLAGS_P(z) & ~ (IS_STR_PERSISTENT | IS_STR_INTERNED | IS_STR_PERMANENT);
122122
ADD_INTERNED_STRING(Z_STR_P(z), 0);
123-
if (IS_INTERNED(Z_STR_P(z))) {
123+
if (!Z_REFCOUNTED_P(z)) {
124124
Z_TYPE_FLAGS_P(z) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
125125
}
126126
Z_GC_FLAGS_P(z) |= flags;

0 commit comments

Comments
 (0)