diff --git a/examples/micro_bench.php b/examples/micro_bench.php index 1ff5a409..27c9af67 100644 --- a/examples/micro_bench.php +++ b/examples/micro_bench.php @@ -339,25 +339,25 @@ function main() $t = end_test($t, '$this->f()', $overhead); $x->read_const(N); $t = end_test($t, '$x = Foo::TEST', $overhead); -// create_object(N); -// $t = end_test($t, 'new Foo()', $overhead); + create_object(N); + $t = end_test($t, 'new Foo()', $overhead); read_const(N); $t = end_test($t, '$x = TEST', $overhead); -// read_auto_global(N); -// $t = end_test($t, '$x = $_GET', $overhead); -// read_global_var(N); -// $t = end_test($t, '$x = $GLOBALS[\'v\']', $overhead); -// read_hash(N); -// $t = end_test($t, '$x = $hash[\'v\']', $overhead); -// read_str_offset(N); -// $t = end_test($t, '$x = $str[0]', $overhead); -// issetor(N); -// $t = end_test($t, '$x = $a ?: null', $overhead); -// issetor2(N); -// $t = end_test($t, '$x = $f ?: tmp', $overhead); -// ternary(N); -// $t = end_test($t, '$x = $f ? $f : $a', $overhead); -// ternary2(N); -// $t = end_test($t, '$x = $f ? $f : tmp', $overhead); + read_auto_global(N); + $t = end_test($t, '$x = $_GET', $overhead); + read_global_var(N); + $t = end_test($t, '$x = $GLOBALS[\'v\']', $overhead); + read_hash(N); + $t = end_test($t, '$x = $hash[\'v\']', $overhead); + read_str_offset(N); + $t = end_test($t, '$x = $str[0]', $overhead); + issetor(N); + $t = end_test($t, '$x = $a ?: null', $overhead); + issetor2(N); + $t = end_test($t, '$x = $f ?: tmp', $overhead); + ternary(N); + $t = end_test($t, '$x = $f ? $f : $a', $overhead); + ternary2(N); + $t = end_test($t, '$x = $f ? $f : tmp', $overhead); total(); } diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index 68276547..ac16f2b6 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -14,8 +14,11 @@ trait FuncCallOptimizer { protected function parseFuncCallWithOptimizer(string $name, Node\Expr\FuncCall $expr): string|false { + $getArg = function ($i) use ($expr) { + return $this->parseIdentifier($expr->args[$i]->value); + }; if ($name === 'strlen' or $name === 'sizeof' or $name === 'count') { - return 'php::len(' . $this->parseIdentifier($expr->args[0]->value) . ')'; + return 'php::len(' . $getArg(0) . ')'; } if (count($expr->args) == 1) { switch ($name) { @@ -42,7 +45,16 @@ trait FuncCallOptimizer } } if ($name === 'abs') { - return 'php::math::abs(' . $this->parseIdentifier($expr->args[0]->value) . ')'; + return 'php::math::abs(' . $getArg(0) . ')'; + } + if ($name === 'ord') { + return 'php::fn::ord(' . $getArg(0) . ')'; + } + if ($name === 'chr') { + return 'php::fn::chr(' . $this->convertIntExpr($getArg(0)) . ')'; + } + if ($name === 'array_key_exists') { + return $getArg(1) . '.offsetExists(' . $getArg(0) . ')'; } if ($name === 'function_exists') { $funcName = $expr->args[0]->value;