Skip to content

Commit 049f7e8

Browse files
authored
spl: use zend_call_known_function() when possible (#22972)
As we don't need to do function cache shenanigans on those calls.
1 parent d52b81e commit 049f7e8

6 files changed

Lines changed: 24 additions & 30 deletions

File tree

ext/spl/spl_array.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static zval *spl_array_read_dimension_ex(int check_inherited, zend_object *objec
426426
ZVAL_UNDEF(&tmp);
427427
offset = &tmp;
428428
}
429-
zend_call_method_with_1_params(object, object->ce, &intern->fptr_offset_get, "offsetGet", rv, offset);
429+
zend_call_known_function(intern->fptr_offset_get, object, object->ce, rv, 1, offset, NULL);
430430

431431
if (!Z_ISUNDEF_P(rv)) {
432432
return rv;
@@ -520,7 +520,7 @@ static void spl_array_unset_dimension_ex(int check_inherited, zend_object *objec
520520
spl_hash_key key;
521521

522522
if (check_inherited && intern->fptr_offset_del) {
523-
zend_call_method_with_1_params(object, object->ce, &intern->fptr_offset_del, "offsetUnset", NULL, offset);
523+
zend_call_known_function(intern->fptr_offset_del, object, object->ce, NULL, 1, offset, NULL);
524524
return;
525525
}
526526

@@ -575,7 +575,7 @@ static bool spl_array_has_dimension_ex(bool check_inherited, zend_object *object
575575
zval rv, *value = NULL, *tmp;
576576

577577
if (check_inherited && intern->fptr_offset_has) {
578-
zend_call_method_with_1_params(object, object->ce, &intern->fptr_offset_has, "offsetExists", &rv, offset);
578+
zend_call_known_function(intern->fptr_offset_has, object, object->ce, &rv, 1, offset, NULL);
579579

580580
if (!zend_is_true(&rv)) {
581581
zval_ptr_dtor(&rv);
@@ -1130,7 +1130,7 @@ static zend_result spl_array_object_count_elements(zend_object *object, zend_lon
11301130

11311131
if (intern->fptr_count) {
11321132
zval rv;
1133-
zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
1133+
zend_call_known_function(intern->fptr_count, object, object->ce, &rv, 0, NULL, NULL);
11341134
if (Z_TYPE(rv) != IS_UNDEF) {
11351135
*count = zval_get_long(&rv);
11361136
zval_ptr_dtor(&rv);
@@ -1811,18 +1811,11 @@ PHP_METHOD(RecursiveArrayIterator, hasChildren)
18111811
}
18121812
/* }}} */
18131813

1814-
static void spl_instantiate_child_arg(zend_class_entry *pce, zval *retval, zval *arg1, zval *arg2) /* {{{ */
1815-
{
1816-
object_init_ex(retval, pce);
1817-
zend_call_known_instance_method_with_2_params(pce->constructor, Z_OBJ_P(retval), NULL, arg1, arg2);
1818-
}
1819-
/* }}} */
1820-
18211814
/* {{{ Create a sub iterator for the current element (same class as $this) */
18221815
PHP_METHOD(RecursiveArrayIterator, getChildren)
18231816
{
1824-
zval *object = ZEND_THIS, *entry, flags;
1825-
spl_array_object *intern = Z_SPLARRAY_P(object);
1817+
zval *entry;
1818+
spl_array_object *intern = Z_SPLARRAY_P(ZEND_THIS);
18261819
HashTable *aht = spl_array_get_hash_table(intern);
18271820

18281821
ZEND_PARSE_PARAMETERS_NONE();
@@ -1845,8 +1838,10 @@ PHP_METHOD(RecursiveArrayIterator, getChildren)
18451838
}
18461839
}
18471840

1848-
ZVAL_LONG(&flags, intern->ar_flags);
1849-
spl_instantiate_child_arg(Z_OBJCE_P(ZEND_THIS), return_value, entry, &flags);
1841+
zval params[2];
1842+
ZVAL_COPY_VALUE(&params[0], entry);
1843+
ZVAL_LONG(&params[1], intern->ar_flags);
1844+
object_init_with_constructor(return_value, Z_OBJCE_P(ZEND_THIS), 2, params, NULL);
18501845
}
18511846
/* }}} */
18521847

ext/spl/spl_directory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static spl_filesystem_object *spl_filesystem_object_create_info(zend_string *fil
480480

481481
if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
482482
ZVAL_STR(&arg1, file_path);
483-
zend_call_method_with_1_params(Z_OBJ_P(return_value), ce, &ce->constructor, "__construct", NULL, &arg1);
483+
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), ce, NULL, 1, &arg1, NULL);
484484
} else {
485485
spl_filesystem_info_set_filename(intern, file_path);
486486
}
@@ -519,7 +519,7 @@ static spl_filesystem_object *spl_filesystem_object_create_type(int num_args, sp
519519

520520
if (ce->constructor->common.scope != spl_ce_SplFileInfo) {
521521
ZVAL_STR(&arg1, source->file_name);
522-
zend_call_method_with_1_params(Z_OBJ_P(return_value), ce, &ce->constructor, "__construct", NULL, &arg1);
522+
zend_call_known_function(ce->constructor, Z_OBJ_P(return_value), ce, NULL, 1, &arg1, NULL);
523523
} else {
524524
intern->file_name = zend_string_copy(source->file_name);
525525
intern->path = spl_filesystem_object_get_path(source);

ext/spl/spl_dllist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static zend_result spl_dllist_object_count_elements(zend_object *object, zend_lo
382382

383383
if (intern->fptr_count) {
384384
zval rv;
385-
zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
385+
zend_call_known_function(intern->fptr_count, object, intern->std.ce, &rv, 0, NULL, NULL);
386386
if (!Z_ISUNDEF(rv)) {
387387
*count = zval_get_long(&rv);
388388
zval_ptr_dtor(&rv);

ext/spl/spl_heap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static zend_result spl_heap_object_count_elements(zend_object *object, zend_long
490490

491491
if (intern->fptr_count) {
492492
zval rv;
493-
zend_call_method_with_0_params(object, intern->std.ce, &intern->fptr_count, "count", &rv);
493+
zend_call_known_function(intern->fptr_count, object, intern->std.ce, &rv, 0, NULL, NULL);
494494
if (!Z_ISUNDEF(rv)) {
495495
*count = zval_get_long(&rv);
496496
zval_ptr_dtor(&rv);

ext/spl/spl_iterators.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static zend_result spl_recursive_it_valid_ex(spl_recursive_it_object *object, zv
213213
level--;
214214
}
215215
if (object->endIteration && object->in_iteration) {
216-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->endIteration, "endIteration", NULL);
216+
zend_call_known_function(object->endIteration, Z_OBJ_P(zthis), object->ce, NULL, 0, NULL, NULL);
217217
}
218218
object->in_iteration = false;
219219
return FAILURE;
@@ -292,7 +292,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
292292
ZEND_FALLTHROUGH;
293293
case RS_TEST:
294294
if (object->callHasChildren) {
295-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->callHasChildren, "callHasChildren", &retval);
295+
zend_call_known_function(object->callHasChildren, Z_OBJ_P(zthis), object->ce, &retval, 0, NULL, NULL);
296296
} else {
297297
zend_class_entry *ce = object->iterators[object->level].ce;
298298
zend_object *obj = Z_OBJ(object->iterators[object->level].zobject);
@@ -333,7 +333,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
333333
}
334334
}
335335
if (object->nextElement) {
336-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->nextElement, "nextelement", NULL);
336+
zend_call_known_function(object->nextElement, Z_OBJ_P(zthis), object->ce, NULL, 0, NULL, NULL);
337337
}
338338
object->iterators[object->level].state = RS_NEXT;
339339
if (EG(exception)) {
@@ -346,7 +346,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
346346
return /* self */;
347347
case RS_SELF:
348348
if (object->nextElement && (object->mode == RIT_SELF_FIRST || object->mode == RIT_CHILD_FIRST)) {
349-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->nextElement, "nextelement", NULL);
349+
zend_call_known_function(object->nextElement, Z_OBJ_P(zthis), object->ce, NULL, 0, NULL, NULL);
350350
}
351351
if (object->mode == RIT_SELF_FIRST) {
352352
object->iterators[object->level].state = RS_CHILD;
@@ -356,7 +356,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
356356
return /* self */;
357357
case RS_CHILD:
358358
if (object->callGetChildren) {
359-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->callGetChildren, "callGetChildren", &child);
359+
zend_call_known_function(object->callGetChildren, Z_OBJ_P(zthis), object->ce, &child, 0, NULL, NULL);
360360
} else {
361361
zend_class_entry *ce = object->iterators[object->level].ce;
362362
zend_object *obj = Z_OBJ(object->iterators[object->level].zobject);
@@ -408,7 +408,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
408408
sub_iter->funcs->rewind(sub_iter);
409409
}
410410
if (object->beginChildren) {
411-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->beginChildren, "beginchildren", NULL);
411+
zend_call_known_function(object->beginChildren, Z_OBJ_P(zthis), object->ce, NULL, 0, NULL, NULL);
412412
if (EG(exception)) {
413413
if (!(object->flags & RIT_CATCH_GET_CHILD)) {
414414
return;
@@ -422,7 +422,7 @@ static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object, zv
422422
/* no more elements */
423423
if (object->level > 0) {
424424
if (object->endChildren) {
425-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->endChildren, "endchildren", NULL);
425+
zend_call_known_function(object->endChildren, Z_OBJ_P(zthis), object->ce, NULL, 0, NULL, NULL);
426426
if (EG(exception)) {
427427
if (!(object->flags & RIT_CATCH_GET_CHILD)) {
428428
return;
@@ -466,7 +466,7 @@ static void spl_recursive_it_rewind_ex(spl_recursive_it_object *object, zval *zt
466466
sub_iter->funcs->rewind(sub_iter);
467467
}
468468
if (!EG(exception) && object->beginIteration && !object->in_iteration) {
469-
zend_call_method_with_0_params(Z_OBJ_P(zthis), object->ce, &object->beginIteration, "beginIteration", NULL);
469+
zend_call_known_function(object->beginIteration, Z_OBJ_P(zthis), object->ce, NULL, 0, NULL, NULL);
470470
}
471471
object->in_iteration = true;
472472
spl_recursive_it_move_forward_ex(object, zthis);
@@ -2824,8 +2824,7 @@ PHP_METHOD(AppendIterator, __construct)
28242824
}
28252825

28262826
intern->dit_type = DIT_AppendIterator;
2827-
object_init_ex(&intern->u.append.zarrayit, spl_ce_ArrayIterator);
2828-
zend_call_method_with_0_params(Z_OBJ(intern->u.append.zarrayit), spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL);
2827+
object_init_with_constructor(&intern->u.append.zarrayit, spl_ce_ArrayIterator, 0, NULL, NULL);
28292828
intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 0);
28302829

28312830
} /* }}} */

ext/spl/spl_observer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static zend_result spl_object_storage_get_hash(zend_hash_key *key, spl_SplObject
9999
ZVAL_OBJ(&param, obj);
100100
ZVAL_UNDEF(&rv);
101101
spl_object_storage_get_hash_depth++;
102-
zend_call_method_with_1_params(&intern->std, intern->std.ce, &intern->fptr_get_hash, "getHash", &rv, &param);
102+
zend_call_known_function(intern->fptr_get_hash, &intern->std, intern->std.ce, &rv, 1, &param, NULL);
103103
spl_object_storage_get_hash_depth--;
104104
if (UNEXPECTED(Z_ISUNDEF(rv))) {
105105
/* An exception has occurred */

0 commit comments

Comments
 (0)