Skip to content

Commit 8afb91c

Browse files
committed
PHP scanner optimization
1 parent d1585a9 commit 8afb91c

File tree

6 files changed

+537
-427
lines changed

6 files changed

+537
-427
lines changed

Zend/zend_compile.c

+2-30
Original file line numberDiff line numberDiff line change
@@ -1675,44 +1675,16 @@ ZEND_API void zend_activate_auto_globals(void) /* {{{ */
16751675
}
16761676
/* }}} */
16771677

1678-
int zendlex(zend_parser_stack_elem *elem) /* {{{ */
1678+
int ZEND_FASTCALL zendlex(zend_parser_stack_elem *elem) /* {{{ */
16791679
{
16801680
zval zv;
1681-
int retval;
1682-
uint32_t start_lineno;
16831681

16841682
if (CG(increment_lineno)) {
16851683
CG(zend_lineno)++;
16861684
CG(increment_lineno) = 0;
16871685
}
16881686

1689-
again:
1690-
ZVAL_UNDEF(&zv);
1691-
start_lineno = CG(zend_lineno);
1692-
retval = lex_scan(&zv);
1693-
if (EG(exception)) {
1694-
return T_ERROR;
1695-
}
1696-
1697-
switch (retval) {
1698-
case T_COMMENT:
1699-
case T_DOC_COMMENT:
1700-
case T_OPEN_TAG:
1701-
case T_WHITESPACE:
1702-
goto again;
1703-
1704-
case T_CLOSE_TAG:
1705-
retval = ';'; /* implicit ; */
1706-
break;
1707-
case T_OPEN_TAG_WITH_ECHO:
1708-
retval = T_ECHO;
1709-
break;
1710-
}
1711-
if (Z_TYPE(zv) != IS_UNDEF) {
1712-
elem->ast = zend_ast_create_zval_with_lineno(&zv, 0, start_lineno);
1713-
}
1714-
1715-
return retval;
1687+
return lex_scan(&zv, elem);
17161688
}
17171689
/* }}} */
17181690

Zend/zend_compile.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ void zend_file_context_end(zend_file_context *prev_context);
691691
extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type);
692692
extern ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename);
693693

694-
ZEND_API int lex_scan(zval *zendlval);
694+
ZEND_API int ZEND_FASTCALL lex_scan(zval *zendlval, zend_parser_stack_elem *elem);
695695
void startup_scanner(void);
696696
void shutdown_scanner(void);
697697

@@ -800,7 +800,7 @@ ZEND_API zend_bool zend_is_auto_global_str(char *name, size_t len);
800800
ZEND_API size_t zend_dirname(char *path, size_t len);
801801
ZEND_API void zend_set_function_arg_flags(zend_function *func);
802802

803-
int zendlex(zend_parser_stack_elem *elem);
803+
int ZEND_FASTCALL zendlex(zend_parser_stack_elem *elem);
804804

805805
int zend_add_literal(zend_op_array *op_array, zval *zv);
806806

Zend/zend_highlight.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
9393
zend_printf("<code>");
9494
zend_printf("<span style=\"color: %s\">\n", last_color);
9595
/* highlight stuff coming back from zendlex() */
96-
ZVAL_UNDEF(&token);
97-
while ((token_type=lex_scan(&token))) {
96+
while ((token_type=lex_scan(&token, NULL))) {
9897
switch (token_type) {
9998
case T_INLINE_HTML:
10099
next_color = syntax_highlighter_ini->highlight_html;
@@ -180,8 +179,7 @@ ZEND_API void zend_strip(void)
180179
int token_type;
181180
int prev_space = 0;
182181

183-
ZVAL_UNDEF(&token);
184-
while ((token_type=lex_scan(&token))) {
182+
while ((token_type=lex_scan(&token, NULL))) {
185183
switch (token_type) {
186184
case T_WHITESPACE:
187185
if (!prev_space) {
@@ -197,7 +195,7 @@ ZEND_API void zend_strip(void)
197195
case T_END_HEREDOC:
198196
zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
199197
/* read the following character, either newline or ; */
200-
if (lex_scan(&token) != T_WHITESPACE) {
198+
if (lex_scan(&token, NULL) != T_WHITESPACE) {
201199
zend_write((char*)LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
202200
}
203201
zend_write("\n", sizeof("\n") - 1);

0 commit comments

Comments
 (0)