mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
Use zend_hash_find() instead of zend_hash_find_ptr() to avoid double check
This commit is contained in:
parent
856ad54f45
commit
a6fcbb7c87
@ -2907,6 +2907,7 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
|
||||
HashTable *ftable;
|
||||
int call_via_handler = 0;
|
||||
zend_class_entry *scope;
|
||||
zval *zv;
|
||||
ALLOCA_FLAG(use_heap)
|
||||
|
||||
if (error) {
|
||||
@ -2927,11 +2928,13 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
|
||||
}
|
||||
/* Check if function with given name exists.
|
||||
* This may be a compound name that includes namespace name */
|
||||
if (EXPECTED((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL)) {
|
||||
zv = zend_hash_find(EG(function_table), lmname);
|
||||
if (EXPECTED(zv != NULL)) {
|
||||
fcc->function_handler = Z_PTR_P(zv);
|
||||
fcc->initialized = 1;
|
||||
if (lmname != Z_STR_P(callable)) {
|
||||
ZSTR_ALLOCA_FREE(lmname, use_heap);
|
||||
}
|
||||
fcc->initialized = 1;
|
||||
return 1;
|
||||
} else {
|
||||
if (lmname == Z_STR_P(callable)) {
|
||||
@ -2940,9 +2943,11 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
|
||||
zend_string_forget_hash_val(lmname);
|
||||
}
|
||||
zend_str_tolower(ZSTR_VAL(lmname), ZSTR_LEN(lmname));
|
||||
if ((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL) {
|
||||
ZSTR_ALLOCA_FREE(lmname, use_heap);
|
||||
zv = zend_hash_find(EG(function_table), lmname);
|
||||
if (zv != NULL) {
|
||||
fcc->function_handler = Z_PTR_P(zv);
|
||||
fcc->initialized = 1;
|
||||
ZSTR_ALLOCA_FREE(lmname, use_heap);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -3010,22 +3015,26 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
|
||||
if (fcc->function_handler) {
|
||||
retval = 1;
|
||||
}
|
||||
} else if ((fcc->function_handler = zend_hash_find_ptr(ftable, lmname)) != NULL) {
|
||||
} else if ((zv = zend_hash_find(ftable, lmname)) != NULL) {
|
||||
fcc->function_handler = Z_PTR_P(zv);
|
||||
retval = 1;
|
||||
if ((fcc->function_handler->op_array.fn_flags & ZEND_ACC_CHANGED) &&
|
||||
!strict_class) {
|
||||
scope = zend_get_executed_scope();
|
||||
if (scope &&
|
||||
instanceof_function(fcc->function_handler->common.scope, scope)) {
|
||||
zend_function *priv_fbc;
|
||||
|
||||
if ((priv_fbc = zend_hash_find_ptr(&scope->function_table, lmname)) != NULL
|
||||
&& priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
|
||||
zv = zend_hash_find(&scope->function_table, lmname);
|
||||
if (zv != NULL) {
|
||||
zend_function *priv_fbc = Z_PTR_P(zv);
|
||||
|
||||
if (priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
|
||||
&& priv_fbc->common.scope == scope) {
|
||||
fcc->function_handler = priv_fbc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((check_flags & IS_CALLABLE_CHECK_NO_ACCESS) == 0 &&
|
||||
(fcc->calling_scope &&
|
||||
((fcc->object && fcc->calling_scope->__call) ||
|
||||
|
@ -262,13 +262,17 @@ ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len)
|
||||
|
||||
ZEND_API zval *zend_get_constant(zend_string *name)
|
||||
{
|
||||
zval *zv;
|
||||
zend_constant *c;
|
||||
ALLOCA_FLAG(use_heap)
|
||||
|
||||
if ((c = zend_hash_find_ptr(EG(zend_constants), name)) == NULL) {
|
||||
zv = zend_hash_find(EG(zend_constants), name);
|
||||
if (zv == NULL) {
|
||||
char *lcname = do_alloca(ZSTR_LEN(name) + 1, use_heap);
|
||||
zend_str_tolower_copy(lcname, ZSTR_VAL(name), ZSTR_LEN(name));
|
||||
if ((c = zend_hash_str_find_ptr(EG(zend_constants), lcname, ZSTR_LEN(name))) != NULL) {
|
||||
zv = zend_hash_str_find(EG(zend_constants), lcname, ZSTR_LEN(name));
|
||||
if (zv != NULL) {
|
||||
c = Z_PTR_P(zv);
|
||||
if (c->flags & CONST_CS) {
|
||||
c = NULL;
|
||||
}
|
||||
@ -276,9 +280,10 @@ ZEND_API zval *zend_get_constant(zend_string *name)
|
||||
c = zend_get_special_constant(ZSTR_VAL(name), ZSTR_LEN(name));
|
||||
}
|
||||
free_alloca(lcname, use_heap);
|
||||
}
|
||||
|
||||
return c ? &c->value : NULL;
|
||||
} else {
|
||||
return &((zend_constant*)Z_PTR_P(zv))->value;
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, uint32_t flags)
|
||||
|
@ -866,7 +866,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) /
|
||||
ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *key, int use_autoload) /* {{{ */
|
||||
{
|
||||
zend_class_entry *ce = NULL;
|
||||
zval args[1];
|
||||
zval args[1], *zv;
|
||||
zval local_retval;
|
||||
zend_string *lc_name;
|
||||
zend_fcall_info fcall_info;
|
||||
@ -887,12 +887,12 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, const zval *k
|
||||
}
|
||||
}
|
||||
|
||||
ce = zend_hash_find_ptr(EG(class_table), lc_name);
|
||||
if (ce) {
|
||||
zv = zend_hash_find(EG(class_table), lc_name);
|
||||
if (zv) {
|
||||
if (!key) {
|
||||
zend_string_release(lc_name);
|
||||
}
|
||||
return ce;
|
||||
return (zend_class_entry*)Z_PTR_P(zv);
|
||||
}
|
||||
|
||||
/* The compiler is not-reentrant. Make sure we __autoload() only during run-time
|
||||
|
Loading…
Reference in New Issue
Block a user