diff --git a/examples/micro_bench.php b/examples/micro_bench.php index 325b6a1b..a14d629c 100644 --- a/examples/micro_bench.php +++ b/examples/micro_bench.php @@ -18,8 +18,10 @@ function hallo2() { function simpleicall($n) { - for ($i = 0; $i < $n; $i++) - $ret = function_exists('hallo'); + for ($i = 0; $i < $n; $i++) { +// $ret = function_exists('hallo'); + $ret = class_exists('Foo2'); + } } class Foo { @@ -169,7 +171,6 @@ function create_object($n) { function read_const($n) { for ($i = 0; $i < $n; ++$i) { -// $x = TEST; $x = TEST_CONST_2; } } @@ -280,11 +281,11 @@ function total() const N = 5000000; const TEST = null; +const TEST_CONST_2 = 1999; function main() { global $total, $last_time, $g_var; - define('TEST_CONST_2', 1999); $g_var = 0; $t0 = $t = start_test(); empty_loop(N); diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index 8490e90e..b3787be2 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -109,6 +109,18 @@ trait FuncCallOptimizer if ($name === 'function_exists') { return $this->genFunctionExists($name, $expr); } + if ($name === 'class_exists') { + $className = $expr->args[0]->value; + if ($this->isScalarString($className) and $this->hasClass($className->value)) { + return 'true'; + } + } + if ($name === 'get_class') { + $object = $expr->args[0]->value; + if ($this->isVarExpr($object) and $this->isTypedObject($object->name)) { + return $this->genCharPtr($this->getObjectType($object->name)); + } + } return false; } @@ -128,9 +140,15 @@ trait FuncCallOptimizer { $funcName = $expr->args[0]->value; if ($this->isScalarString($funcName)) { - $funcName = $this->getLiteralString(strtolower(trim($funcName->value, '\\'))); + $nameLower = strtolower(trim($funcName->value, '\\')); + if ($this->findNativeFunction($nameLower)) { + return 'true'; + } + $funcName = $this->getLiteralString($nameLower); return 'php::fn::function_exists(' . $funcName . ', true)'; } return 'php::fn::function_exists(' . $this->parseIdentifier($funcName) . ')'; } + + } diff --git a/tests/aot/functions/get_class.phpt b/tests/aot/functions/get_class.phpt new file mode 100644 index 00000000..141e8683 --- /dev/null +++ b/tests/aot/functions/get_class.phpt @@ -0,0 +1,17 @@ +--TEST-- +class const 001 +--FILE-- + +--EXPECT-- +string(6) "Worker" \ No newline at end of file