Skip to content

Commit 63c7b63

Browse files
committed
Improved optimzations and namespace handling, courtesy Arnaud.
1 parent 241dda7 commit 63c7b63

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Zend/zend_compile.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6437,19 +6437,29 @@ static void zend_compile_pipe(znode *result, zend_ast *ast)
64376437
znode wrapped_operand_result;
64386438
zend_emit_op_tmp(&wrapped_operand_result, ZEND_QM_ASSIGN, &operand_result, NULL);
64396439

6440+
zend_ast *arg_list_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, zend_ast_create_znode(&wrapped_operand_result));
6441+
zend_ast *fcall_ast;
6442+
6443+
znode callable_result;
6444+
64406445
/* Turn $foo |> bar(...) into bar($foo). */
64416446
if (callable_ast->kind == ZEND_AST_CALL
64426447
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) {
6443-
callable_ast = callable_ast->child[0];
6448+
fcall_ast = zend_ast_create(ZEND_AST_CALL,
6449+
callable_ast->child[0], arg_list_ast);
6450+
/* Turn $foo |> $bar->baz(...) into $bar->baz($foo). */
6451+
} else if (callable_ast->kind == ZEND_AST_METHOD_CALL
6452+
&& callable_ast->child[2]->kind == ZEND_AST_CALLABLE_CONVERT) {
6453+
fcall_ast = zend_ast_create(ZEND_AST_METHOD_CALL,
6454+
callable_ast->child[0], callable_ast->child[1], arg_list_ast);
6455+
/* Turn $foo |> $expr into ($expr)($foo) */
6456+
} else {
6457+
zend_compile_expr(&callable_result, callable_ast);
6458+
callable_ast = zend_ast_create_znode(&callable_result);
6459+
fcall_ast = zend_ast_create(ZEND_AST_CALL,
6460+
callable_ast, arg_list_ast);
64446461
}
64456462

6446-
znode callable_result;
6447-
zend_compile_expr(&callable_result, callable_ast);
6448-
6449-
zend_ast *fcall_ast = zend_ast_create(ZEND_AST_CALL,
6450-
zend_ast_create_znode(&callable_result),
6451-
zend_ast_create_list(1, ZEND_AST_ARG_LIST, zend_ast_create_znode(&wrapped_operand_result)));
6452-
64536463
zend_compile_expr(result, fcall_ast);
64546464
}
64556465

0 commit comments

Comments
 (0)