isset() micro-optimisation

This commit is contained in:
Dmitry Stogov 2015-06-03 16:27:38 +03:00
parent b21191ba78
commit ce2a78939d
2 changed files with 338 additions and 364 deletions

View file

@ -6618,8 +6618,7 @@ ZEND_VM_C_LABEL(num_index_prop):
ZEND_VM_C_GOTO(isset_again); ZEND_VM_C_GOTO(isset_again);
default: default:
zend_error(E_WARNING, "Illegal offset type in isset or empty"); zend_error(E_WARNING, "Illegal offset type in isset or empty");
value = NULL; ZEND_VM_C_GOTO(isset_not_found);
break;
} }
} }
@ -6639,42 +6638,42 @@ ZEND_VM_C_LABEL(num_index_prop):
} }
if (OP1_TYPE == IS_UNUSED || EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) { if (OP1_TYPE == IS_UNUSED || EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
if (EXPECTED(Z_OBJ_HT_P(container)->has_dimension)) { if (EXPECTED(Z_OBJ_HT_P(container)->has_dimension)) {
result = Z_OBJ_HT_P(container)->has_dimension(container, offset, (opline->extended_value & ZEND_ISSET) == 0); result =
((opline->extended_value & ZEND_ISSET) == 0) ^
Z_OBJ_HT_P(container)->has_dimension(container, offset, (opline->extended_value & ZEND_ISSET) == 0);
} else { } else {
zend_error(E_NOTICE, "Trying to check element of non-array"); zend_error(E_NOTICE, "Trying to check element of non-array");
result = 0; ZEND_VM_C_GOTO(isset_not_found);
}
if ((opline->extended_value & ZEND_ISSET) == 0) {
result = !result;
} }
} else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */ } else if (EXPECTED(Z_TYPE_P(container) == IS_STRING)) { /* string offsets */
zval tmp; zend_long lval;
result = 0; if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
if (UNEXPECTED(Z_TYPE_P(offset) != IS_LONG)) { lval = Z_LVAL_P(offset);
ZEND_VM_C_LABEL(isset_str_offset):
if (EXPECTED(lval >= 0) && (size_t)lval < Z_STRLEN_P(container)) {
if (opline->extended_value & ZEND_ISSET) {
result = 1;
} else {
result = (Z_STRVAL_P(container)[lval] == '0');
}
} else {
ZEND_VM_C_GOTO(isset_not_found);
}
} else {
if (OP2_TYPE & (IS_CV|IS_VAR)) { if (OP2_TYPE & (IS_CV|IS_VAR)) {
ZVAL_DEREF(offset); ZVAL_DEREF(offset);
} }
if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */ if (Z_TYPE_P(offset) < IS_STRING /* simple scalar types */
|| (Z_TYPE_P(offset) == IS_STRING /* or numeric string */ || (Z_TYPE_P(offset) == IS_STRING /* or numeric string */
&& IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) { && IS_LONG == is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), NULL, NULL, 0))) {
ZVAL_DUP(&tmp, offset); lval = zval_get_long(offset);
convert_to_long(&tmp); ZEND_VM_C_GOTO(isset_str_offset);
offset = &tmp;
} }
} ZEND_VM_C_GOTO(isset_not_found);
if (EXPECTED(Z_TYPE_P(offset) == IS_LONG)) {
if (offset->value.lval >= 0 && (size_t)offset->value.lval < Z_STRLEN_P(container)) {
if ((opline->extended_value & ZEND_ISSET) ||
Z_STRVAL_P(container)[offset->value.lval] != '0') {
result = 1;
}
}
}
if ((opline->extended_value & ZEND_ISSET) == 0) {
result = !result;
} }
} else { } else {
ZEND_VM_C_LABEL(isset_not_found):
result = ((opline->extended_value & ZEND_ISSET) == 0); result = ((opline->extended_value & ZEND_ISSET) == 0);
} }
@ -6721,10 +6720,9 @@ ZEND_VM_HANDLER(148, ZEND_ISSET_ISEMPTY_PROP_OBJ, CONST|TMPVAR|UNUSED|CV, CONST|
ZEND_VM_C_LABEL(isset_no_object): ZEND_VM_C_LABEL(isset_no_object):
result = ((opline->extended_value & ZEND_ISSET) == 0); result = ((opline->extended_value & ZEND_ISSET) == 0);
} else { } else {
result = Z_OBJ_HT_P(container)->has_property(container, offset, (opline->extended_value & ZEND_ISSET) == 0, ((OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(offset)) : NULL)); result =
if ((opline->extended_value & ZEND_ISSET) == 0) { ((opline->extended_value & ZEND_ISSET) == 0) ^
result = !result; Z_OBJ_HT_P(container)->has_property(container, offset, (opline->extended_value & ZEND_ISSET) == 0, ((OP2_TYPE == IS_CONST) ? CACHE_ADDR(Z_CACHE_SLOT_P(offset)) : NULL));
}
} }
FREE_OP2(); FREE_OP2();

File diff suppressed because it is too large Load diff