summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2017-12-27 13:26:06 +0300
committerDmitry Stogov <dmitry@zend.com>2017-12-27 13:26:06 +0300
commita6fcbb7c8709d20a471d81839e320693f7636a34 (patch)
tree0d0918b6ba1ae2b12b92db8fcca19453af7ecf90 /Zend
parent856ad54f4504e1659797f84f8b951e6f80918da3 (diff)
downloadphp-git-a6fcbb7c8709d20a471d81839e320693f7636a34.tar.gz
Use zend_hash_find() instead of zend_hash_find_ptr() to avoid double check
Diffstat (limited to 'Zend')
-rw-r--r--Zend/zend_API.c29
-rw-r--r--Zend/zend_constants.c13
-rw-r--r--Zend/zend_execute_API.c8
3 files changed, 32 insertions, 18 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 7e19683094..4fea589dfc 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -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,19 +3015,23 @@ 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
- && priv_fbc->common.scope == scope) {
- fcc->function_handler = priv_fbc;
+ 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;
+ }
}
}
}
diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c
index 42bccda28f..fa6d156a6e 100644
--- a/Zend/zend_constants.c
+++ b/Zend/zend_constants.c
@@ -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;
}
-
- return c ? &c->value : NULL;
}
ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope, uint32_t flags)
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c
index 8e366ca75c..f2f9b55009 100644
--- a/Zend/zend_execute_API.c
+++ b/Zend/zend_execute_API.c
@@ -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