Skip to content

Commit 5e997ec

Browse files
authored
Remove special self/parent handling in get_class_name_map_ptr() (php#7330)
zend_accel_get_class_name_map_ptr() for "self" and "parent" will currently try to determine which class these refer to, and then initialize the CE_CACHE on those strings. However, this shouldn't be necessary: We already initialize CE_CACHE on all class declaration names, so it should be covered through that already.
1 parent 3533250 commit 5e997ec

File tree

4 files changed

+10
-29
lines changed

4 files changed

+10
-29
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static void accel_allocate_ce_cache_slots(void)
750750

751751
ce = (zend_class_entry*)Z_PTR(p->val);
752752
if (ce->name) {
753-
zend_accel_get_class_name_map_ptr(ce->name, ce, /* have_xlat */ false);
753+
zend_accel_get_class_name_map_ptr(ce->name);
754754
}
755755
} ZEND_HASH_FOREACH_END();
756756
}

ext/opcache/ZendAccelerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type);
318318

319319
zend_string* ZEND_FASTCALL accel_new_interned_string(zend_string *str);
320320

321-
uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name, zend_class_entry *scope, bool have_xlat);
321+
uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name);
322322

323323
/* memory write protection */
324324
#define SHM_PROTECT() \

ext/opcache/zend_file_cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ static void zend_file_cache_unserialize_type(
12311231
UNSERIALIZE_STR(type_name);
12321232
ZEND_TYPE_SET_PTR(*type, type_name);
12331233
if (!script->corrupted) {
1234-
zend_accel_get_class_name_map_ptr(type_name, scope, /* have_xlat */ false);
1234+
zend_accel_get_class_name_map_ptr(type_name);
12351235
}
12361236
} else if (ZEND_TYPE_HAS_CE(*type)) {
12371237
zend_class_entry *ce = ZEND_TYPE_CE(*type);
@@ -1499,7 +1499,7 @@ static void zend_file_cache_unserialize_class(zval *zv,
14991499
UNSERIALIZE_STR(ce->name);
15001500
if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)
15011501
&& !script->corrupted) {
1502-
zend_accel_get_class_name_map_ptr(ce->name, ce, /* have_xlat */ false);
1502+
zend_accel_get_class_name_map_ptr(ce->name);
15031503
}
15041504
if (ce->parent) {
15051505
if (!(ce->ce_flags & ZEND_ACC_LINKED)) {

ext/opcache/zend_persist.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -298,32 +298,13 @@ static HashTable *zend_persist_attributes(HashTable *attributes)
298298
return ptr;
299299
}
300300

301-
uint32_t zend_accel_get_class_name_map_ptr(
302-
zend_string *type_name, zend_class_entry *scope, bool have_xlat)
301+
uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name)
303302
{
304303
uint32_t ret;
305304

306-
if (zend_string_equals_literal_ci(type_name, "self")) {
307-
if (!scope || (scope->ce_flags & ZEND_ACC_TRAIT)) {
308-
return 0;
309-
}
310-
type_name = scope->name;
311-
} else if (zend_string_equals_literal_ci(type_name, "parent")) {
312-
if (!scope || !scope->parent) {
313-
return 0;
314-
}
315-
if (scope->ce_flags & ZEND_ACC_RESOLVED_PARENT) {
316-
/* This runs before zend_update_parent_ce(), so manually fetch the persisted parent
317-
* class, as the original may be no longer valid. */
318-
zend_class_entry *new_parent;
319-
if (have_xlat && (new_parent = zend_shared_alloc_get_xlat_entry(scope->parent))) {
320-
type_name = new_parent->name;
321-
} else {
322-
type_name = scope->parent->name;
323-
}
324-
} else {
325-
type_name = scope->parent_name;
326-
}
305+
if (zend_string_equals_literal_ci(type_name, "self") ||
306+
zend_string_equals_literal_ci(type_name, "parent")) {
307+
return 0;
327308
}
328309

329310
/* We use type.name.gc.refcount to keep map_ptr of corresponding type */
@@ -383,7 +364,7 @@ static void zend_persist_type(zend_type *type, zend_class_entry *scope) {
383364
zend_accel_store_interned_string(type_name);
384365
ZEND_TYPE_SET_PTR(*single_type, type_name);
385366
if (!ZCG(current_persistent_script)->corrupted) {
386-
zend_accel_get_class_name_map_ptr(type_name, scope, /* have_xlat */ true);
367+
zend_accel_get_class_name_map_ptr(type_name);
387368
}
388369
}
389370
} ZEND_TYPE_FOREACH_END();
@@ -893,7 +874,7 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
893874
if (ZSTR_HAS_CE_CACHE(ce->name)) {
894875
ZSTR_SET_CE_CACHE(ce->name, NULL);
895876
} else {
896-
zend_accel_get_class_name_map_ptr(ce->name, ce, /* have_xlat */ true);
877+
zend_accel_get_class_name_map_ptr(ce->name);
897878
}
898879
}
899880
if (ce->parent_name && !(ce->ce_flags & ZEND_ACC_LINKED)) {

0 commit comments

Comments
 (0)