[PHP-CVS] [php-src] master: Zend: Use pointer hash lookups for methods

[email protected] (Weilin Du)
Newsgroups php.cvs
Message-ID <[email protected]>
Author: Weilin Du (LamentXU123)
Date: 2026-08-16T16:35:06+08:00

Commit: https://github.com/php/php-src/commit/d3f0e07df3360f7efb4c02fc5857e3ba74aa4a17
Raw diff: https://github.com/php/php-src/commit/d3f0e07df3360f7efb4c02fc5857e3ba74aa4a17.diff

Zend: Use pointer hash lookups for methods

Changed paths:
  M  Zend/zend_API.c
  M  Zend/zend_object_handlers.c


Diff:

diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index a03ceb8cd28b..b5bea957106b 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3802,7 +3802,6 @@ static zend_always_inline bool zend_is_method_callable(zend_string *callable, co
 	HashTable *ftable;
 	bool call_via_handler = false;
 	zend_class_entry *scope;
-	zval *zv;
 
 	fcc->calling_scope = NULL;
 
@@ -3888,8 +3887,7 @@ static zend_always_inline bool zend_is_method_callable(zend_string *callable, co
 		if (fcc->function_handler) {
 			retval = true;
 		}
-	} else if ((zv = zend_hash_find(ftable, lmname)) != NULL) {
-		fcc->function_handler = Z_PTR_P(zv);
+	} else if ((fcc->function_handler = zend_hash_find_ptr(ftable, lmname)) != NULL) {
 		retval = true;
 		if ((fcc->function_handler->op_array.fn_flags & ZEND_ACC_CHANGED) &&
 		    !strict_class) {
@@ -3897,10 +3895,8 @@ static zend_always_inline bool zend_is_method_callable(zend_string *callable, co
 			if (scope &&
 			    instanceof_function(fcc->function_handler->common.scope, scope)) {
 
-				zv = zend_hash_find(&scope->function_table, lmname);
-				if (zv != NULL) {
-					zend_function *priv_fbc = Z_PTR_P(zv);
-
+				zend_function *priv_fbc = zend_hash_find_ptr(&scope->function_table, lmname);
+				if (priv_fbc != NULL) {
 					if ((priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE)
 					 && priv_fbc->common.scope == scope) {
 						fcc->function_handler = priv_fbc;
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index e06287895d15..f3b925cdeb31 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -1756,13 +1756,9 @@ ZEND_API void zend_std_unset_dimension(zend_object *object, zval *offset) /* {{{
 
 static zend_never_inline zend_function *zend_get_parent_private_method(const zend_class_entry *scope, const zend_class_entry *ce, zend_string *function_name) /* {{{ */
 {
-	zval *func;
-	zend_function *fbc;
-
 	if (scope != ce && scope && is_derived_class(ce, scope)) {
-		func = zend_hash_find(&scope->function_table, function_name);
-		if (func != NULL) {
-			fbc = Z_FUNC_P(func);
+		zend_function *fbc = zend_hash_find_ptr(&scope->function_table, function_name);
+		if (fbc != NULL) {
 			if ((fbc->common.fn_flags & ZEND_ACC_PRIVATE)
 			 && fbc->common.scope == scope) {
 				return fbc;
@@ -1979,7 +1975,6 @@ ZEND_API ZEND_COLD zend_never_inline void zend_abstract_method_call(const zend_f
 ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key) /* {{{ */
 {
 	zend_object *zobj = *obj_ptr;
-	zval *func;
 	zend_function *fbc;
 	zend_string *lc_method_name;
 	ALLOCA_FLAG(use_heap);
@@ -1994,7 +1989,8 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
 		zend_str_tolower_copy(ZSTR_VAL(lc_method_name), ZSTR_VAL(method_name), ZSTR_LEN(method_name));
 	}
 
-	if (UNEXPECTED((func = zend_hash_find(&zobj->ce->function_table, lc_method_name)) == NULL)) {
+	fbc = zend_hash_find_ptr(&zobj->ce->function_table, lc_method_name);
+	if (UNEXPECTED(fbc == NULL)) {
 		if (UNEXPECTED(!key)) {
 			ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
 		}
@@ -2005,8 +2001,6 @@ ZEND_API zend_function *zend_std_get_method(zend_object **obj_ptr, zend_string *
 		}
 	}
 
-	fbc = Z_FUNC_P(func);
-
 	/* Check access level */
 	if (fbc->op_array.fn_flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
 		const zend_class_entry *scope = zend_get_executed_scope();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.