Skip to content

Commit f0dd79a

Browse files
committed
Optimize ArrayAccess method lookup
While these currently aren't cached in the class entry, we can at least save us a lowercasing and hash calculation of the method name.
1 parent 7504cf1 commit f0dd79a

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Zend/zend_object_handlers.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,9 @@ ZEND_API zval *zend_std_read_dimension(zend_object *object, zval *offset, int ty
918918

919919
GC_ADDREF(object);
920920
if (type == BP_VAR_IS) {
921-
zend_call_method_with_1_params(object, ce, NULL, "offsetexists", rv, &tmp_offset);
921+
zend_function *offsetexists =
922+
zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_OFFSETEXISTS));
923+
zend_call_known_instance_method_with_1_params(offsetexists, object, rv, &tmp_offset);
922924
if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
923925
OBJ_RELEASE(object);
924926
zval_ptr_dtor(&tmp_offset);
@@ -933,7 +935,9 @@ ZEND_API zval *zend_std_read_dimension(zend_object *object, zval *offset, int ty
933935
zval_ptr_dtor(rv);
934936
}
935937

936-
zend_call_method_with_1_params(object, ce, NULL, "offsetget", rv, &tmp_offset);
938+
zend_function *offsetget =
939+
zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_OFFSETGET));
940+
zend_call_known_instance_method_with_1_params(offsetget, object, rv, &tmp_offset);
937941

938942
OBJ_RELEASE(object);
939943
zval_ptr_dtor(&tmp_offset);
@@ -964,7 +968,9 @@ ZEND_API void zend_std_write_dimension(zend_object *object, zval *offset, zval *
964968
ZVAL_COPY_DEREF(&tmp_offset, offset);
965969
}
966970
GC_ADDREF(object);
967-
zend_call_method_with_2_params(object, ce, NULL, "offsetset", NULL, &tmp_offset, value);
971+
zend_function *offsetset =
972+
zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_OFFSETSET));
973+
zend_call_known_instance_method_with_2_params(offsetset, object, NULL, &tmp_offset, value);
968974
OBJ_RELEASE(object);
969975
zval_ptr_dtor(&tmp_offset);
970976
} else {
@@ -982,11 +988,15 @@ ZEND_API int zend_std_has_dimension(zend_object *object, zval *offset, int check
982988
if (EXPECTED(zend_class_implements_interface(ce, zend_ce_arrayaccess) != 0)) {
983989
ZVAL_COPY_DEREF(&tmp_offset, offset);
984990
GC_ADDREF(object);
985-
zend_call_method_with_1_params(object, ce, NULL, "offsetexists", &retval, &tmp_offset);
991+
zend_function *offsetexists =
992+
zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_OFFSETEXISTS));
993+
zend_call_known_instance_method_with_1_params(offsetexists, object, &retval, &tmp_offset);
986994
result = i_zend_is_true(&retval);
987995
zval_ptr_dtor(&retval);
988996
if (check_empty && result && EXPECTED(!EG(exception))) {
989-
zend_call_method_with_1_params(object, ce, NULL, "offsetget", &retval, &tmp_offset);
997+
zend_function *offsetget =
998+
zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_OFFSETGET));
999+
zend_call_known_instance_method_with_1_params(offsetget, object, &retval, &tmp_offset);
9901000
result = i_zend_is_true(&retval);
9911001
zval_ptr_dtor(&retval);
9921002
}
@@ -1163,7 +1173,9 @@ ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset) /* {{{
11631173
if (zend_class_implements_interface(ce, zend_ce_arrayaccess)) {
11641174
ZVAL_COPY_DEREF(&tmp_offset, offset);
11651175
GC_ADDREF(object);
1166-
zend_call_method_with_1_params(object, ce, NULL, "offsetunset", NULL, &tmp_offset);
1176+
zend_function *offsetunset =
1177+
zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_OFFSETUNSET));
1178+
zend_call_known_instance_method_with_1_params(offsetunset, object, NULL, &tmp_offset);
11671179
OBJ_RELEASE(object);
11681180
zval_ptr_dtor(&tmp_offset);
11691181
} else {

Zend/zend_string.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ EMPTY_SWITCH_DEFAULT_CASE()
570570
_(ZEND_STR_AUTOGLOBAL_SERVER, "_SERVER") \
571571
_(ZEND_STR_AUTOGLOBAL_ENV, "_ENV") \
572572
_(ZEND_STR_AUTOGLOBAL_REQUEST, "_REQUEST") \
573+
_(ZEND_STR_OFFSETGET, "offsetget") \
574+
_(ZEND_STR_OFFSETSET, "offsetset") \
575+
_(ZEND_STR_OFFSETEXISTS, "offsetexists") \
576+
_(ZEND_STR_OFFSETUNSET, "offsetunset") \
573577

574578

575579
typedef enum _zend_known_string_id {

0 commit comments

Comments
 (0)