Skip to content

Commit 9c18395

Browse files
committed
enhance
1 parent f032844 commit 9c18395

File tree

2 files changed

+31
-40
lines changed

2 files changed

+31
-40
lines changed

Zend/zend_API.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ static int compare_simple_types(const zend_type a, const zend_type b) {
29242924
if (a_has_name && b_has_name) {
29252925
const zend_string *a_name = ZEND_TYPE_NAME(a);
29262926
const zend_string *b_name = ZEND_TYPE_NAME(b);
2927-
const int cmp = zend_string_equals_ci(a_name, b_name);
2927+
const int cmp = ZSTR_VAL(a_name) - ZSTR_VAL(b_name);
29282928
if (cmp != 0) {
29292929
return cmp;
29302930
}
@@ -3107,7 +3107,7 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(const zend_type type) {
31073107

31083108
size_t deduped_count = 0;
31093109
for (size_t i = 0; i < num_children; i++) {
3110-
if (i == 0 || compare_type_nodes(&children[i], &children[i - 1]) != 0) {
3110+
if (i == 0 || children[i] != children[i - 1]) {
31113111
children[deduped_count++] = children[i];
31123112
}
31133113
}
@@ -3117,6 +3117,7 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(const zend_type type) {
31173117
node->compound.num_types = deduped_count;
31183118
node->compound.types = pemalloc(sizeof(zend_type_node *) * deduped_count, 1);
31193119
memcpy(node->compound.types, children, sizeof(zend_type_node *) * deduped_count);
3120+
pefree(children, 1);
31203121

31213122
return intern_type_node(node);
31223123
}

Zend/zend_execute.c

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,10 @@ static zend_always_inline bool zend_value_instanceof_static(zval *zv) {
11121112
static zend_always_inline zend_class_entry *zend_fetch_ce_from_cache_slot(
11131113
void **cache_slot, zend_type *type)
11141114
{
1115-
if (EXPECTED(HAVE_CACHE_SLOT && *cache_slot)) {
1116-
return (zend_class_entry *) *cache_slot;
1117-
}
1115+
// todo: work with cache_slot
1116+
//if (EXPECTED(HAVE_CACHE_SLOT && *cache_slot)) {
1117+
// return (zend_class_entry *) *cache_slot;
1118+
//}
11181119

11191120
zend_string *name = ZEND_TYPE_NAME(*type);
11201121
zend_class_entry *ce;
@@ -1140,58 +1141,47 @@ static zend_always_inline zend_class_entry *zend_fetch_ce_from_cache_slot(
11401141
return ce;
11411142
}
11421143

1143-
static int zend_type_node_matches(const zend_type_node *node, zval *zv)
1144-
{
1145-
switch (node->kind) {
1146-
case ZEND_TYPE_SIMPLE: {
1147-
return 2;
1148-
}
11491144

1150-
case ZEND_TYPE_UNION: {
1151-
for (uint32_t i = 0; i < node->compound.num_types; i++) {
1152-
if (zend_type_node_matches(node->compound.types[i], zv)) {
1153-
return 1;
1145+
static bool zend_check_type_slow(
1146+
zend_type *type, zend_type_node *type_tree, zval *arg, zend_reference *ref, void **cache_slot,
1147+
bool is_return_type, bool is_internal)
1148+
{
1149+
if (EXPECTED(type_tree != NULL) && type_tree->kind != ZEND_TYPE_SIMPLE) {
1150+
switch (type_tree->kind) {
1151+
case ZEND_TYPE_UNION: {
1152+
for (uint32_t i = 0; i < type_tree->compound.num_types; i++) {
1153+
if (zend_check_type_slow(type, type_tree->compound.types[i], arg, ref, cache_slot, is_return_type, is_internal)) {
1154+
return true;
1155+
}
11541156
}
1157+
return false;
11551158
}
1156-
return 0;
1157-
}
11581159

1159-
case ZEND_TYPE_INTERSECTION: {
1160-
for (uint32_t i = 0; i < node->compound.num_types; i++) {
1161-
if (!zend_type_node_matches(node->compound.types[i], zv)) {
1162-
return 0;
1160+
case ZEND_TYPE_INTERSECTION: {
1161+
for (uint32_t i = 0; i < type_tree->compound.num_types; i++) {
1162+
if (!zend_check_type_slow(type, type_tree->compound.types[i], arg, ref, cache_slot, is_return_type, is_internal)) {
1163+
return false;
1164+
}
11631165
}
1166+
return true;
11641167
}
1165-
return 1;
1166-
}
1167-
1168-
default:
1169-
return 0;
1170-
}
1171-
}
11721168

1173-
1174-
static zend_always_inline bool zend_check_type_slow(
1175-
zend_type *type, zend_type_node *type_tree, zval *arg, zend_reference *ref, void **cache_slot,
1176-
bool is_return_type, bool is_internal)
1177-
{
1178-
if (EXPECTED(type_tree != NULL) && type_tree->kind != ZEND_TYPE_SIMPLE) {
1179-
const int result = zend_type_node_matches(type_tree, arg);
1180-
if (result < 2) {
1181-
return result;
1169+
default:
1170+
return false;
11821171
}
11831172
}
11841173

1185-
if (ZEND_TYPE_IS_COMPLEX(*type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
1186-
const zend_class_entry *ce = zend_fetch_ce_from_cache_slot(cache_slot, type);
1174+
if (ZEND_TYPE_IS_COMPLEX(type_tree->simple_type) && EXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
1175+
const zend_class_entry *ce = zend_fetch_ce_from_cache_slot(cache_slot, &type_tree->simple_type);
11871176
/* If we have a CE we check if it satisfies the type constraint,
11881177
* otherwise it will check if a standard type satisfies it. */
11891178
if (ce && instanceof_function(Z_OBJCE_P(arg), ce)) {
11901179
return true;
11911180
}
1181+
PROGRESS_CACHE_SLOT();
11921182
}
11931183

1194-
const uint32_t type_mask = ZEND_TYPE_FULL_MASK(*type);
1184+
const uint32_t type_mask = ZEND_TYPE_FULL_MASK(type_tree->simple_type);
11951185
if ((type_mask & MAY_BE_CALLABLE) &&
11961186
zend_is_callable(arg, is_internal ? IS_CALLABLE_SUPPRESS_DEPRECATIONS : 0, NULL)) {
11971187
return 1;

0 commit comments

Comments
 (0)