com php-src: Optimize instanceof_class/interface: Zend/ze nd_operators.c
| From: | Nikita Popov | Date: | Thu, 24 Oct 2019 15:47:35 +0000 |
| Subject: | com php-src: Optimize instanceof_class/interface: Zend/ze nd_operators.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-109051@lists.php.net to get a copy of this message | ||
Commit: c63a0e005abe4b00ab097dc47ca53d20788a6361
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 24 Oct 2019 17:47:35 +0200
Parents: 435f2691088fa9011696fd331d401544155d69a9
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c63a0e005abe4b00ab097dc47ca53d20788a6361
Log:
Optimize instanceof_class/interface
instanceof_class does not need to check for a NULL pointer in the
first iteration -- passing NULL to this function is illegal.
instanceof_interface does not need to use instanceof_class(), it
only has to check whether the CEs match exactly. There is no way
for an interface to appear inside "parent", it will always be in
"interfaces" only.
Changed paths:
M Zend/zend_operators.c
Diff:
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index bf896a8befc..c2ea3cd65ac 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -2311,12 +2311,12 @@ ZEND_API int ZEND_FASTCALL is_smaller_or_equal_function(zval *result, zval
*op1,
static zend_always_inline zend_bool instanceof_class(const zend_class_entry *instance_ce, const
zend_class_entry *ce) /* {{{ */
{
- while (instance_ce) {
+ do {
if (instance_ce == ce) {
return 1;
}
instance_ce = instance_ce->parent;
- }
+ } while (instance_ce);
return 0;
}
/* }}} */
@@ -2333,7 +2333,7 @@ static zend_bool ZEND_FASTCALL instanceof_interface(const zend_class_entry
*inst
}
}
}
- return instanceof_class(instance_ce, ce);
+ return instance_ce == ce;
}
/* }}} */