Skip to content

Commit 78f2a1b

Browse files
committed
Optimize ReflectionProperty constructor
Perform HT lookups using a zend_string. Don't copy the name for the "name" property. We can always use the original name directly, as properties case case-sensitive, so the original name should always match the unmangled name of the fetched property info.
1 parent 9b02ee0 commit 78f2a1b

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

ext/reflection/php_reflection.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,16 +5289,15 @@ ZEND_METHOD(reflection_class_constant, export)
52895289
ZEND_METHOD(reflection_property, __construct)
52905290
{
52915291
zval propname, cname, *classname;
5292-
char *name_str;
5293-
size_t name_len;
5292+
zend_string *name;
52945293
int dynam_prop = 0;
52955294
zval *object;
52965295
reflection_object *intern;
52975296
zend_class_entry *ce;
52985297
zend_property_info *property_info = NULL;
52995298
property_reference *reference;
53005299

5301-
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) {
5300+
if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zS", &classname, &name) == FAILURE) {
53025301
return;
53035302
}
53045303

@@ -5324,15 +5323,15 @@ ZEND_METHOD(reflection_property, __construct)
53245323
/* returns out of this function */
53255324
}
53265325

5327-
if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, name_str, name_len)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) {
5326+
if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) {
53285327
/* Check for dynamic properties */
53295328
if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) {
5330-
if (zend_hash_str_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name_str, name_len)) {
5329+
if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name)) {
53315330
dynam_prop = 1;
53325331
}
53335332
}
53345333
if (dynam_prop == 0) {
5335-
zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), name_str);
5334+
zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
53365335
return;
53375336
}
53385337
}
@@ -5342,24 +5341,21 @@ ZEND_METHOD(reflection_property, __construct)
53425341
zend_class_entry *tmp_ce = ce;
53435342
zend_property_info *tmp_info;
53445343

5345-
while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, name_str, name_len)) == NULL) {
5344+
while (tmp_ce && (tmp_info = zend_hash_find_ptr(&tmp_ce->properties_info, name)) == NULL) {
53465345
ce = tmp_ce;
53475346
property_info = tmp_info;
53485347
tmp_ce = tmp_ce->parent;
53495348
}
53505349
}
53515350

53525351
if (dynam_prop == 0) {
5353-
const char *class_name, *prop_name;
5354-
size_t prop_name_len;
5355-
zend_unmangle_property_name_ex(property_info->name, &class_name, &prop_name, &prop_name_len);
53565352
ZVAL_STR_COPY(&cname, property_info->ce->name);
5357-
ZVAL_STRINGL(&propname, prop_name, prop_name_len);
53585353
} else {
53595354
ZVAL_STR_COPY(&cname, ce->name);
5360-
ZVAL_STRINGL(&propname, name_str, name_len);
53615355
}
53625356
reflection_update_property_class(object, &cname);
5357+
5358+
ZVAL_STR_COPY(&propname, name);
53635359
reflection_update_property_name(object, &propname);
53645360

53655361
reference = (property_reference*) emalloc(sizeof(property_reference));

0 commit comments

Comments
 (0)