Skip to content

Commit 2d4bb4f

Browse files
committed
Use string destructor instead of general zval_ptr_dtor_nogc()
1 parent f58c645 commit 2d4bb4f

File tree

2 files changed

+369
-123
lines changed

2 files changed

+369
-123
lines changed

Zend/zend_vm_def.h

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,29 +310,39 @@ ZEND_VM_HANDLER(8, ZEND_CONCAT, CONST|TMPVAR|CV, CONST|TMPVAR|CV, SPEC(NO_CONST_
310310
} else {
311311
ZVAL_STR(EX_VAR(opline->result.var), op2_str);
312312
}
313-
FREE_OP1();
313+
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
314+
zend_string_release_ex(op1_str, 0);
315+
}
314316
} else if (OP2_TYPE != IS_CONST && UNEXPECTED(ZSTR_LEN(op2_str) == 0)) {
315317
if (OP1_TYPE == IS_CONST || OP1_TYPE == IS_CV) {
316318
ZVAL_STR_COPY(EX_VAR(opline->result.var), op1_str);
317319
} else {
318320
ZVAL_STR(EX_VAR(opline->result.var), op1_str);
319321
}
320-
FREE_OP2();
322+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
323+
zend_string_release_ex(op2_str, 0);
324+
}
321325
} else if (OP1_TYPE != IS_CONST && OP1_TYPE != IS_CV &&
322326
!ZSTR_IS_INTERNED(op1_str) && GC_REFCOUNT(op1_str) == 1) {
323327
size_t len = ZSTR_LEN(op1_str);
324328

325329
str = zend_string_extend(op1_str, len + ZSTR_LEN(op2_str), 0);
326330
memcpy(ZSTR_VAL(str) + len, ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
327331
ZVAL_NEW_STR(EX_VAR(opline->result.var), str);
328-
FREE_OP2();
332+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
333+
zend_string_release_ex(op2_str, 0);
334+
}
329335
} else {
330336
str = zend_string_alloc(ZSTR_LEN(op1_str) + ZSTR_LEN(op2_str), 0);
331337
memcpy(ZSTR_VAL(str), ZSTR_VAL(op1_str), ZSTR_LEN(op1_str));
332338
memcpy(ZSTR_VAL(str) + ZSTR_LEN(op1_str), ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
333339
ZVAL_NEW_STR(EX_VAR(opline->result.var), str);
334-
FREE_OP1();
335-
FREE_OP2();
340+
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
341+
zend_string_release_ex(op1_str, 0);
342+
}
343+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
344+
zend_string_release_ex(op2_str, 0);
345+
}
336346
}
337347
ZEND_VM_NEXT_OPCODE();
338348
} else {
@@ -426,8 +436,12 @@ ZEND_VM_C_LABEL(is_equal_double):
426436
} else if (EXPECTED(Z_TYPE_P(op1) == IS_STRING)) {
427437
if (EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
428438
int result = zend_fast_equal_strings(Z_STR_P(op1), Z_STR_P(op2));
429-
FREE_OP1();
430-
FREE_OP2();
439+
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
440+
zval_ptr_dtor_str(op1);
441+
}
442+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
443+
zval_ptr_dtor_str(op2);
444+
}
431445
if (result) {
432446
ZEND_VM_C_GOTO(is_equal_true);
433447
} else {
@@ -500,8 +514,12 @@ ZEND_VM_C_LABEL(is_not_equal_double):
500514
} else if (EXPECTED(Z_TYPE_P(op1) == IS_STRING)) {
501515
if (EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
502516
int result = zend_fast_equal_strings(Z_STR_P(op1), Z_STR_P(op2));
503-
FREE_OP1();
504-
FREE_OP2();
517+
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
518+
zval_ptr_dtor_str(op1);
519+
}
520+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
521+
zval_ptr_dtor_str(op2);
522+
}
505523
if (!result) {
506524
ZEND_VM_C_GOTO(is_not_equal_true);
507525
} else {
@@ -3037,29 +3055,39 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(53, ZEND_FAST_CONCAT, CONST|TMPVAR|CV, CONST|TMP
30373055
} else {
30383056
ZVAL_STR(EX_VAR(opline->result.var), op2_str);
30393057
}
3040-
FREE_OP1();
3058+
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
3059+
zend_string_release_ex(op1_str, 0);
3060+
}
30413061
} else if (OP2_TYPE != IS_CONST && UNEXPECTED(ZSTR_LEN(op2_str) == 0)) {
30423062
if (OP1_TYPE == IS_CONST || OP1_TYPE == IS_CV) {
30433063
ZVAL_STR_COPY(EX_VAR(opline->result.var), op1_str);
30443064
} else {
30453065
ZVAL_STR(EX_VAR(opline->result.var), op1_str);
30463066
}
3047-
FREE_OP2();
3067+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
3068+
zend_string_release_ex(op2_str, 0);
3069+
}
30483070
} else if (OP1_TYPE != IS_CONST && OP1_TYPE != IS_CV &&
30493071
!ZSTR_IS_INTERNED(op1_str) && GC_REFCOUNT(op1_str) == 1) {
30503072
size_t len = ZSTR_LEN(op1_str);
30513073

30523074
str = zend_string_extend(op1_str, len + ZSTR_LEN(op2_str), 0);
30533075
memcpy(ZSTR_VAL(str) + len, ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
30543076
ZVAL_NEW_STR(EX_VAR(opline->result.var), str);
3055-
FREE_OP2();
3077+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
3078+
zend_string_release_ex(op2_str, 0);
3079+
}
30563080
} else {
30573081
str = zend_string_alloc(ZSTR_LEN(op1_str) + ZSTR_LEN(op2_str), 0);
30583082
memcpy(ZSTR_VAL(str), ZSTR_VAL(op1_str), ZSTR_LEN(op1_str));
30593083
memcpy(ZSTR_VAL(str) + ZSTR_LEN(op1_str), ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
30603084
ZVAL_NEW_STR(EX_VAR(opline->result.var), str);
3061-
FREE_OP1();
3062-
FREE_OP2();
3085+
if (OP1_TYPE & (IS_TMP_VAR|IS_VAR)) {
3086+
zend_string_release_ex(op1_str, 0);
3087+
}
3088+
if (OP2_TYPE & (IS_TMP_VAR|IS_VAR)) {
3089+
zend_string_release_ex(op2_str, 0);
3090+
}
30633091
}
30643092
ZEND_VM_NEXT_OPCODE();
30653093
}

0 commit comments

Comments
 (0)