com php-src: improve performance: Zend/zend_execute.c Zen d/zend_execute.h Zend/zend_types.h
| From: | Bob Weinand | Date: | Mon, 23 May 2016 10:08:06 +0000 |
| Subject: | com php-src: improve performance: Zend/zend_execute.c Zen d/zend_execute.h Zend/zend_types.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95561@lists.php.net to get a copy of this message | ||
Commit: 2a5daa7ecf04cfab1e3aafacbec824329c251243
Author: Joe Watkins <krakjoe@php.net> Mon, 23 May 2016 11:08:06 +0100
Parents: 304ff494623bd62d3e2fc9ce8250e5ca3c4ca8b8
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2a5daa7ecf04cfab1e3aafacbec824329c251243
Log:
improve performance
Changed paths:
M Zend/zend_execute.c
M Zend/zend_execute.h
M Zend/zend_types.h
Diff:
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 25bfa3f..3eb27ac 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -793,53 +793,6 @@ static int zend_verify_internal_arg_type(zend_function *zf, uint32_t arg_num,
zv
return 1;
}
-zend_property_info* zend_object_fetch_property_type_info_ex(zval *object, zend_string *property,
void **cache_slot) {
- zend_property_info *info = NULL;
-
- if (cache_slot && EXPECTED(Z_OBJCE_P(object) == CACHED_PTR_EX(cache_slot))) {
- zend_property_info *cached = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
-
- return (cached && cached->type) ? cached : NULL;
- }
-
- info = zend_get_property_info(Z_OBJCE_P(object), property, 1);
-
- if (UNEXPECTED(info && info != ZEND_WRONG_PROPERTY_INFO && info->type)) {
- return info;
- }
-
- return NULL;
-}
-
-zend_property_info* zend_object_fetch_property_type_info(zval *object, zval *property, void
**cache_slot)
-{
- if (cache_slot && EXPECTED(Z_OBJCE_P(object) == CACHED_PTR_EX(cache_slot))) {
- zend_property_info *info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
-
- return (info && info->type) ? info : NULL;
- }
-
- do {
- if (UNEXPECTED(Z_TYPE_P(property) != IS_STRING)) {
- break;
- }
-
- if (UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
- if (Z_ISREF_P(object)) {
- object = Z_REFVAL_P(object);
- if (Z_TYPE_P(object) != IS_OBJECT)
- break;
- } else {
- break;
- }
- }
-
- return zend_object_fetch_property_type_info_ex(object, Z_STR_P(property), cache_slot);
- } while (0);
-
- return NULL;
-}
-
static inline zend_bool zend_verify_scalar_property_type(zend_uchar type, zval *property, zend_bool
strict) {
if (EXPECTED(!strict)) {
if (UNEXPECTED(!ZEND_SAME_FAKE_TYPE(type, Z_TYPE_P(property)))) {
@@ -883,7 +836,12 @@ void zend_verify_property_type_error(zend_property_info *info, zend_string
*name
}
zend_bool zend_verify_property_type(zend_property_info *info, zval *property, zend_bool strict) {
+ if (EXPECTED((Z_TYPE_FLAGS_P(property) & IS_TYPE_VERIFIED) != 0)) {
+ return 1;
+ }
+
if (EXPECTED(ZEND_SAME_FAKE_TYPE(info->type, Z_TYPE_P(property)) && Z_TYPE_P(property)
!= IS_OBJECT)) {
+ Z_TYPE_FLAGS_P(property) |= IS_TYPE_VERIFIED;
return 1;
}
@@ -898,23 +856,34 @@ zend_bool zend_verify_property_type(zend_property_info *info, zval *property,
ze
if (!info->type_ce || Z_TYPE_P(property) != IS_OBJECT ||
!instanceof_function(Z_OBJCE_P(property), info->type_ce)) {
return 0;
}
+
+ Z_TYPE_FLAGS_P(property) |= IS_TYPE_VERIFIED;
return 1;
}
case IS_CALLABLE: switch (Z_TYPE_P(property)) {
case IS_OBJECT:
- if (instanceof_function(zend_ce_closure, Z_OBJCE_P(property)))
+ if (instanceof_function(zend_ce_closure, Z_OBJCE_P(property))) {
+ Z_TYPE_FLAGS_P(property) |= IS_TYPE_VERIFIED;
return 1;
+ }
+ case IS_STRING:
case IS_ARRAY:
- if (zend_is_callable(property, IS_CALLABLE_CHECK_SILENT, NULL))
+ if (zend_is_callable(property, IS_CALLABLE_CHECK_SILENT, NULL)) {
+ Z_TYPE_FLAGS_P(property) |= IS_TYPE_VERIFIED;
return 1;
+ }
+
+ default:
+ return 0;
}
default:
if (!zend_verify_scalar_property_type(info->type, property, strict)) {
return 0;
}
+ Z_TYPE_FLAGS_P(property) |= IS_TYPE_VERIFIED;
return 1;
}
}
@@ -1552,7 +1521,7 @@ static zend_never_inline void zend_assign_op_overloaded_property(zval *object,
z
zptr = z;
ZVAL_DEREF(z);
SEPARATE_ZVAL_NOREF(z);
-
+
if (UNEXPECTED(ZEND_CLASS_HAS_TYPE_HINTS(Z_OBJCE(obj)) && Z_TYPE_P(property) ==
IS_STRING)) {
zend_property_info *prop_info = zend_object_fetch_property_type_info_ex(object,
Z_STR_P(property), cache_slot);
diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h
index 2d20865..b853f4f 100644
--- a/Zend/zend_execute.h
+++ b/Zend/zend_execute.h
@@ -392,8 +392,53 @@ static zend_always_inline zend_bool _zend_object_has_type_hints(zval *object) {
#define ZEND_OBJECT_HAS_TYPE_HINTS(object) _zend_object_has_type_hints(object)
-zend_property_info* zend_object_fetch_property_type_info(zval *object, zval *property, void
**cache);
-zend_property_info* zend_object_fetch_property_type_info_ex(zval *object, zend_string *property,
void **cache);
+static zend_always_inline zend_property_info* zend_object_fetch_property_type_info_ex(zval *object,
zend_string *property, void **cache_slot) {
+ zend_property_info *info = NULL;
+
+ if (cache_slot && EXPECTED(Z_OBJCE_P(object) == CACHED_PTR_EX(cache_slot))) {
+ zend_property_info *cached = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
+
+ return (cached && cached->type) ? cached : NULL;
+ }
+
+ info = zend_get_property_info(Z_OBJCE_P(object), property, 1);
+
+ if (UNEXPECTED(info && info != ZEND_WRONG_PROPERTY_INFO && info->type)) {
+ return info;
+ }
+
+ return NULL;
+}
+
+static zend_always_inline zend_property_info* zend_object_fetch_property_type_info(zval *object,
zval *property, void **cache_slot)
+{
+ if (cache_slot && EXPECTED(Z_OBJCE_P(object) == CACHED_PTR_EX(cache_slot))) {
+ zend_property_info *info = (zend_property_info*)CACHED_PTR_EX(cache_slot + 2);
+
+ return (info && info->type) ? info : NULL;
+ }
+
+ do {
+ if (UNEXPECTED(Z_TYPE_P(property) != IS_STRING)) {
+ break;
+ }
+
+ if (UNEXPECTED(Z_TYPE_P(object) != IS_OBJECT)) {
+ if (Z_ISREF_P(object)) {
+ object = Z_REFVAL_P(object);
+ if (Z_TYPE_P(object) != IS_OBJECT)
+ break;
+ } else {
+ break;
+ }
+ }
+
+ return zend_object_fetch_property_type_info_ex(object, Z_STR_P(property), cache_slot);
+ } while (0);
+
+ return NULL;
+}
+
zend_bool zend_verify_property_type(zend_property_info *info, zval *property, zend_bool strict);
void zend_verify_property_type_error(zend_property_info *info, zend_string *name, zval *property);
diff --git a/Zend/zend_types.h b/Zend/zend_types.h
index 5207386..ec6b399 100644
--- a/Zend/zend_types.h
+++ b/Zend/zend_types.h
@@ -398,6 +398,7 @@ static zend_always_inline zend_uchar zval_get_type(const zval* pz) {
#define IS_TYPE_REFCOUNTED (1<<2)
#define IS_TYPE_COLLECTABLE (1<<3)
#define IS_TYPE_COPYABLE (1<<4)
+#define IS_TYPE_VERIFIED (1<<5)
/* extended types */
#define IS_INTERNED_STRING_EX IS_STRING