com php-src: Implement ZEND_STRLEN optimization: Zend/z end_compile.c
| From: | Nikita Popov | Date: | Tue, 22 Jul 2014 20:57:38 +0000 |
| Subject: | com php-src: Implement ZEND_STRLEN optimization: Zend/z end_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-80958@lists.php.net to get a copy of this message | ||
Commit: 2ee490ba3abb6cbccb3c8c4eead0f03cf8ceff17
Author: Nikita Popov <nikic@php.net> Tue, 22 Jul 2014 22:57:38 +0200
Parents: f21d8bc23b11d016bc56382538c7b4faea318eff
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2ee490ba3abb6cbccb3c8c4eead0f03cf8ceff17
Log:
Implement ZEND_STRLEN optimization
Changed paths:
M Zend/zend_compile.c
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index a20e24c..8c217a4 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3517,6 +3517,12 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
}
/* }}} */
+static inline zend_bool zend_str_equals(zend_string *str, char *c) {
+ size_t len = strlen(c);
+ return str->len == len && !memcmp(str->val, c, len);
+}
+
+
static void zend_adjust_for_fetch_type(zend_op *opline, zend_uint type) {
switch (type & BP_VAR_MASK) {
case BP_VAR_R:
@@ -4284,6 +4290,12 @@ zend_bool zend_args_contain_unpack(zend_ast *args) {
return 0;
}
+void zend_compile_func_strlen(znode *result, zend_ast *ast TSRMLS_DC) {
+ znode expr_node;
+ zend_compile_expr(&expr_node, ast TSRMLS_CC);
+ emit_op(result, ZEND_STRLEN, &expr_node, NULL TSRMLS_CC);
+}
+
void zend_compile_call(znode *result, zend_ast *ast, int type TSRMLS_DC) {
zend_ast *name_ast = ast->child[0];
zend_ast *args_ast = ast->child[1];
@@ -4312,6 +4324,17 @@ void zend_compile_call(znode *result, zend_ast *ast, int type TSRMLS_DC) {
zend_str_tolower_copy(lcname->val, Z_STRVAL_P(name), Z_STRLEN_P(name));
+ if (zend_str_equals(lcname, "strlen")) {
+ if (!(CG(compiler_options) & ZEND_COMPILE_NO_BUILTIN_STRLEN)
+ && args_ast->children == 1 && args_ast->child[0]->kind !=
ZEND_AST_UNPACK
+ ) {
+ STR_FREE(lcname);
+ zval_ptr_dtor(&name_node.u.constant);
+ zend_compile_func_strlen(result, args_ast->child[0] TSRMLS_CC);
+ return;
+ }
+ }
+
if (!(fbc = zend_hash_find_ptr(CG(function_table), lcname)) ||
((CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS) &&
fbc->type == ZEND_INTERNAL_FUNCTION)
@@ -5340,11 +5363,6 @@ void zend_compile_closure_uses(zend_ast *ast TSRMLS_DC) {
}
}
-static inline zend_bool zend_str_equals(zend_string *str, char *c) {
- size_t len = strlen(c);
- return str->len == len && !memcmp(str->val, c, len);
-}
-
void zend_begin_method_decl(
zend_op_array *op_array, zend_string *name, zend_bool has_body TSRMLS_DC
) {