Skip to content

Commit dc30e1d

Browse files
committed
Cleanup SPL instantiation code
1 parent fc4d462 commit dc30e1d

File tree

3 files changed

+13
-48
lines changed

3 files changed

+13
-48
lines changed

ext/spl/spl_engine.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@
2929

3030
#include "spl_array.h"
3131

32-
/* {{{ spl_instantiate */
33-
PHPAPI void spl_instantiate(zend_class_entry *pce, zval *object)
34-
{
35-
object_init_ex(object, pce);
36-
}
37-
/* }}} */
38-
3932
PHPAPI zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
4033
{
4134
zend_ulong idx;

ext/spl/spl_engine.h

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,27 @@
2121
#include "php_spl.h"
2222
#include "zend_interfaces.h"
2323

24-
PHPAPI void spl_instantiate(zend_class_entry *pce, zval *object);
25-
2624
PHPAPI zend_long spl_offset_convert_to_long(zval *offset);
2725

28-
/* {{{ spl_instantiate_arg_ex1 */
29-
static inline int spl_instantiate_arg_ex1(zend_class_entry *pce, zval *retval, zval *arg1)
26+
static inline void spl_instantiate_arg_ex1(zend_class_entry *pce, zval *retval, zval *arg1)
3027
{
31-
zend_function *func = pce->constructor;
32-
spl_instantiate(pce, retval);
33-
34-
zend_call_method(Z_OBJ_P(retval), pce, &func, ZSTR_VAL(func->common.function_name), ZSTR_LEN(func->common.function_name), NULL, 1, arg1, NULL);
35-
return 0;
28+
object_init_ex(retval, pce);
29+
zend_call_known_instance_method_with_1_params(pce->constructor, Z_OBJ_P(retval), NULL, arg1);
3630
}
37-
/* }}} */
3831

39-
/* {{{ spl_instantiate_arg_ex2 */
40-
static inline int spl_instantiate_arg_ex2(zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2)
32+
static inline void spl_instantiate_arg_ex2(
33+
zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2)
4134
{
42-
zend_function *func = pce->constructor;
43-
spl_instantiate(pce, retval);
44-
45-
zend_call_method(Z_OBJ_P(retval), pce, &func, ZSTR_VAL(func->common.function_name), ZSTR_LEN(func->common.function_name), NULL, 2, arg1, arg2);
46-
return 0;
35+
object_init_ex(retval, pce);
36+
zend_call_known_instance_method_with_2_params(
37+
pce->constructor, Z_OBJ_P(retval), NULL, arg1, arg2);
4738
}
48-
/* }}} */
4939

50-
/* {{{ spl_instantiate_arg_n */
51-
static inline void spl_instantiate_arg_n(zend_class_entry *pce, zval *retval, int argc, zval *argv)
40+
static inline void spl_instantiate_arg_n(
41+
zend_class_entry *pce, zval *retval, uint32_t argc, zval *argv)
5242
{
53-
zend_function *func = pce->constructor;
54-
zend_fcall_info fci;
55-
zend_fcall_info_cache fcc;
56-
zval dummy;
57-
58-
spl_instantiate(pce, retval);
59-
60-
fci.size = sizeof(zend_fcall_info);
61-
ZVAL_STR(&fci.function_name, func->common.function_name);
62-
fci.object = Z_OBJ_P(retval);
63-
fci.retval = &dummy;
64-
fci.param_count = argc;
65-
fci.params = argv;
66-
67-
fcc.function_handler = func;
68-
fcc.called_scope = pce;
69-
fcc.object = Z_OBJ_P(retval);
70-
71-
zend_call_function(&fci, &fcc);
43+
object_init_ex(retval, pce);
44+
zend_call_known_instance_method(pce->constructor, Z_OBJ_P(retval), NULL, argc, argv);
7245
}
73-
/* }}} */
7446

7547
#endif /* SPL_ENGINE_H */

ext/spl/spl_iterators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
13651365
}
13661366
intern->dit_type = DIT_AppendIterator;
13671367
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
1368-
spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit);
1368+
object_init_ex(&intern->u.append.zarrayit, spl_ce_ArrayIterator);
13691369
zend_call_method_with_0_params(Z_OBJ(intern->u.append.zarrayit), spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL);
13701370
intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 0);
13711371
zend_restore_error_handling(&error_handling);

0 commit comments

Comments
 (0)