Skip to content

Commit 937fa6d

Browse files
TysonAndredstogov
authored andcommitted
Optimize is_scalar($x) into a TYPE_CHECK opcode
Optimizations such as specializations for is_resource were first added in dfb4f6b38d9efedafab7d2d98b9333715561256 I don't see any mention of is_scalar (and optimizing it) in the commit history, or in prior PRs on github, or searching for is_scalar in externals.io
1 parent ad0a3f2 commit 937fa6d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Zend/zend_compile.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,21 @@ int zend_compile_func_typecheck(znode *result, zend_ast_list *args, uint32_t typ
33943394
}
33953395
/* }}} */
33963396

3397+
static int zend_compile_func_is_scalar(znode *result, zend_ast_list *args) /* {{{ */
3398+
{
3399+
znode arg_node;
3400+
zend_op *opline;
3401+
3402+
if (args->children != 1) {
3403+
return FAILURE;
3404+
}
3405+
3406+
zend_compile_expr(&arg_node, args->child[0]);
3407+
opline = zend_emit_op_tmp(result, ZEND_TYPE_CHECK, &arg_node, NULL);
3408+
opline->extended_value = (1 << IS_FALSE | 1 << IS_TRUE | 1 << IS_DOUBLE | 1 << IS_LONG | 1 << IS_STRING);
3409+
return SUCCESS;
3410+
}
3411+
33973412
int zend_compile_func_cast(znode *result, zend_ast_list *args, uint32_t type) /* {{{ */
33983413
{
33993414
znode arg_node;
@@ -3912,6 +3927,8 @@ int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_l
39123927
return zend_compile_func_typecheck(result, args, IS_OBJECT);
39133928
} else if (zend_string_equals_literal(lcname, "is_resource")) {
39143929
return zend_compile_func_typecheck(result, args, IS_RESOURCE);
3930+
} else if (zend_string_equals_literal(lcname, "is_scalar")) {
3931+
return zend_compile_func_is_scalar(result, args);
39153932
} else if (zend_string_equals_literal(lcname, "boolval")) {
39163933
return zend_compile_func_cast(result, args, _IS_BOOL);
39173934
} else if (zend_string_equals_literal(lcname, "intval")) {

0 commit comments

Comments
 (0)