Skip to content

Commit 62e53e6

Browse files
Inline and remove reflection_instantiate() (php#16739)
Since the return value is never used, the only difference between using this method and using `object_init_ex()` directly is the flipped order of parameters, and the added level of indirection - remove that level of indirection by replacing its uses.
1 parent 4e21e80 commit 62e53e6

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

ext/reflection/php_reflection.c

+12-19
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,6 @@ static zend_object *reflection_objects_new(zend_class_entry *class_type) /* {{{
301301
}
302302
/* }}} */
303303

304-
static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{ */
305-
{
306-
object_init_ex(object, pce);
307-
return object;
308-
}
309-
/* }}} */
310-
311304
static void _const_string(smart_str *str, const char *name, zval *value, const char *indent);
312305
static void _function_string(smart_str *str, zend_function *fptr, zend_class_entry *scope, const char* indent);
313306
static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, const char* indent);
@@ -1168,7 +1161,7 @@ static void reflection_attribute_factory(zval *object, HashTable *attributes, ze
11681161
reflection_object *intern;
11691162
attribute_reference *reference;
11701163

1171-
reflection_instantiate(reflection_attribute_ptr, object);
1164+
object_init_ex(object, reflection_attribute_ptr);
11721165
intern = Z_REFLECTION_P(object);
11731166
reference = (attribute_reference*) emalloc(sizeof(attribute_reference));
11741167
reference->attributes = attributes;
@@ -1316,7 +1309,7 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object)
13161309

13171310
zend_class_entry *reflection_ce =
13181311
ce->ce_flags & ZEND_ACC_ENUM ? reflection_enum_ptr : reflection_class_ptr;
1319-
reflection_instantiate(reflection_ce, object);
1312+
object_init_ex(object, reflection_ce);
13201313
intern = Z_REFLECTION_P(object);
13211314
intern->ptr = ce;
13221315
intern->ref_type = REF_TYPE_OTHER;
@@ -1328,7 +1321,7 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object)
13281321
/* {{{ reflection_extension_factory_ex */
13291322
static void reflection_extension_factory_ex(zval *object, zend_module_entry *module)
13301323
{
1331-
reflection_instantiate(reflection_extension_ptr, object);
1324+
object_init_ex(object, reflection_extension_ptr);
13321325
reflection_object *intern = Z_REFLECTION_P(object);
13331326
intern->ptr = module;
13341327
intern->ref_type = REF_TYPE_OTHER;
@@ -1363,7 +1356,7 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje
13631356
parameter_reference *reference;
13641357
zval *prop_name;
13651358

1366-
reflection_instantiate(reflection_parameter_ptr, object);
1359+
object_init_ex(object, reflection_parameter_ptr);
13671360
intern = Z_REFLECTION_P(object);
13681361
reference = (parameter_reference*) emalloc(sizeof(parameter_reference));
13691362
reference->arg_info = arg_info;
@@ -1438,13 +1431,13 @@ static void reflection_type_factory(zend_type type, zval *object, bool legacy_be
14381431

14391432
switch (type_kind) {
14401433
case INTERSECTION_TYPE:
1441-
reflection_instantiate(reflection_intersection_type_ptr, object);
1434+
object_init_ex(object, reflection_intersection_type_ptr);
14421435
break;
14431436
case UNION_TYPE:
1444-
reflection_instantiate(reflection_union_type_ptr, object);
1437+
object_init_ex(object, reflection_union_type_ptr);
14451438
break;
14461439
case NAMED_TYPE:
1447-
reflection_instantiate(reflection_named_type_ptr, object);
1440+
object_init_ex(object, reflection_named_type_ptr);
14481441
break;
14491442
EMPTY_SWITCH_DEFAULT_CASE();
14501443
}
@@ -1471,7 +1464,7 @@ static void reflection_type_factory(zend_type type, zval *object, bool legacy_be
14711464
static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object)
14721465
{
14731466
reflection_object *intern;
1474-
reflection_instantiate(reflection_function_ptr, object);
1467+
object_init_ex(object, reflection_function_ptr);
14751468
intern = Z_REFLECTION_P(object);
14761469
intern->ptr = function;
14771470
intern->ref_type = REF_TYPE_FUNCTION;
@@ -1488,7 +1481,7 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho
14881481
{
14891482
reflection_object *intern;
14901483

1491-
reflection_instantiate(reflection_method_ptr, object);
1484+
object_init_ex(object, reflection_method_ptr);
14921485
intern = Z_REFLECTION_P(object);
14931486
intern->ptr = method;
14941487
intern->ref_type = REF_TYPE_FUNCTION;
@@ -1508,7 +1501,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_string *name,
15081501
reflection_object *intern;
15091502
property_reference *reference;
15101503

1511-
reflection_instantiate(reflection_property_ptr, object);
1504+
object_init_ex(object, reflection_property_ptr);
15121505
intern = Z_REFLECTION_P(object);
15131506
reference = (property_reference*) emalloc(sizeof(property_reference));
15141507
reference->prop = prop;
@@ -1533,7 +1526,7 @@ static void reflection_class_constant_factory(zend_string *name_str, zend_class_
15331526
{
15341527
reflection_object *intern;
15351528

1536-
reflection_instantiate(reflection_class_constant_ptr, object);
1529+
object_init_ex(object, reflection_class_constant_ptr);
15371530
intern = Z_REFLECTION_P(object);
15381531
intern->ptr = constant;
15391532
intern->ref_type = REF_TYPE_CLASS_CONSTANT;
@@ -1551,7 +1544,7 @@ static void reflection_enum_case_factory(zend_class_entry *ce, zend_string *name
15511544
zend_class_entry *case_reflection_class = ce->enum_backing_type == IS_UNDEF
15521545
? reflection_enum_unit_case_ptr
15531546
: reflection_enum_backed_case_ptr;
1554-
reflection_instantiate(case_reflection_class, object);
1547+
object_init_ex(object, case_reflection_class);
15551548
intern = Z_REFLECTION_P(object);
15561549
intern->ptr = constant;
15571550
intern->ref_type = REF_TYPE_CLASS_CONSTANT;

0 commit comments

Comments
 (0)