Don't copy in ZEND_CAST if type is already correct

This commit is contained in:
Nikita Popov 2014-04-16 22:39:01 +02:00
parent 320bf772c6
commit f98937fa80
3 changed files with 61 additions and 26 deletions

View File

@ -6209,7 +6209,7 @@ void zend_do_cast(znode *result, const znode *expr, int type TSRMLS_DC) /* {{{ *
zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
opline->opcode = ZEND_CAST;
opline->result_type = IS_TMP_VAR;
opline->result_type = IS_VAR;
opline->result.var = get_temporary_variable(CG(active_op_array));
SET_NODE(opline->op1, expr);
SET_UNUSED(opline->op2);

View File

@ -3726,6 +3726,18 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY)
SAVE_OPLINE();
expr = GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R);
if (Z_TYPE_P(expr) == opline->extended_value) {
ZVAL_COPY_VALUE(result, expr);
if (OP1_TYPE == IS_CV) {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
} else if (OP1_TYPE == IS_CONST) {
zval_opt_copy_ctor(result);
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
if (opline->extended_value != IS_STRING) {
ZVAL_COPY_VALUE(result, expr);
if (!IS_OP1_TMP_FREE()) {
@ -3733,7 +3745,6 @@ ZEND_VM_HANDLER(21, ZEND_CAST, CONST|TMP|VAR|CV, ANY)
}
}
ZEND_VM_C_LABEL(cast_again):
switch (opline->extended_value) {
case IS_NULL:
convert_to_null(result);
@ -3771,10 +3782,6 @@ ZEND_VM_C_LABEL(cast_again):
case IS_OBJECT:
convert_to_object(result);
break;
case IS_REFERENCE:
result = Z_REFVAL_P(result);
ZEND_VM_C_GOTO(cast_again);
break;
}
FREE_OP1_IF_VAR();
CHECK_EXCEPTION();

View File

@ -2756,6 +2756,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
SAVE_OPLINE();
expr = opline->op1.zv;
if (Z_TYPE_P(expr) == opline->extended_value) {
ZVAL_COPY_VALUE(result, expr);
if (IS_CONST == IS_CV) {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
} else if (IS_CONST == IS_CONST) {
zval_opt_copy_ctor(result);
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
if (opline->extended_value != IS_STRING) {
ZVAL_COPY_VALUE(result, expr);
if (!0) {
@ -2763,7 +2775,6 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
}
}
cast_again:
switch (opline->extended_value) {
case IS_NULL:
convert_to_null(result);
@ -2801,10 +2812,6 @@ cast_again:
case IS_OBJECT:
convert_to_object(result);
break;
case IS_REFERENCE:
result = Z_REFVAL_P(result);
goto cast_again;
break;
}
CHECK_EXCEPTION();
@ -7693,6 +7700,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
SAVE_OPLINE();
expr = _get_zval_ptr_tmp(opline->op1.var, execute_data, &free_op1 TSRMLS_CC);
if (Z_TYPE_P(expr) == opline->extended_value) {
ZVAL_COPY_VALUE(result, expr);
if (IS_TMP_VAR == IS_CV) {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
} else if (IS_TMP_VAR == IS_CONST) {
zval_opt_copy_ctor(result);
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
if (opline->extended_value != IS_STRING) {
ZVAL_COPY_VALUE(result, expr);
if (!1) {
@ -7700,7 +7719,6 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
}
}
cast_again:
switch (opline->extended_value) {
case IS_NULL:
convert_to_null(result);
@ -7738,10 +7756,6 @@ cast_again:
case IS_OBJECT:
convert_to_object(result);
break;
case IS_REFERENCE:
result = Z_REFVAL_P(result);
goto cast_again;
break;
}
CHECK_EXCEPTION();
@ -12672,6 +12686,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
SAVE_OPLINE();
expr = _get_zval_ptr_var_deref(opline->op1.var, execute_data, &free_op1 TSRMLS_CC);
if (Z_TYPE_P(expr) == opline->extended_value) {
ZVAL_COPY_VALUE(result, expr);
if (IS_VAR == IS_CV) {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
} else if (IS_VAR == IS_CONST) {
zval_opt_copy_ctor(result);
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
if (opline->extended_value != IS_STRING) {
ZVAL_COPY_VALUE(result, expr);
if (!0) {
@ -12679,7 +12705,6 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
}
}
cast_again:
switch (opline->extended_value) {
case IS_NULL:
convert_to_null(result);
@ -12717,10 +12742,6 @@ cast_again:
case IS_OBJECT:
convert_to_object(result);
break;
case IS_REFERENCE:
result = Z_REFVAL_P(result);
goto cast_again;
break;
}
zval_ptr_dtor_nogc(free_op1.var);
CHECK_EXCEPTION();
@ -29181,6 +29202,18 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
SAVE_OPLINE();
expr = _get_zval_ptr_cv_deref_BP_VAR_R(execute_data, opline->op1.var TSRMLS_CC);
if (Z_TYPE_P(expr) == opline->extended_value) {
ZVAL_COPY_VALUE(result, expr);
if (IS_CV == IS_CV) {
if (Z_OPT_REFCOUNTED_P(expr)) Z_ADDREF_P(expr);
} else if (IS_CV == IS_CONST) {
zval_opt_copy_ctor(result);
}
CHECK_EXCEPTION();
ZEND_VM_NEXT_OPCODE();
}
if (opline->extended_value != IS_STRING) {
ZVAL_COPY_VALUE(result, expr);
if (!0) {
@ -29188,7 +29221,6 @@ static int ZEND_FASTCALL ZEND_CAST_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
}
}
cast_again:
switch (opline->extended_value) {
case IS_NULL:
convert_to_null(result);
@ -29226,10 +29258,6 @@ cast_again:
case IS_OBJECT:
convert_to_object(result);
break;
case IS_REFERENCE:
result = Z_REFVAL_P(result);
goto cast_again;
break;
}
CHECK_EXCEPTION();