refactor(php): 优化函数调用优化器中的function_exists处理

- 移除CompilerBase.php中多余的空行
- 重构FuncCallOptimizer.php中的function_exists逻辑,支持字符串字面量的大小写转换和转义处理
- 在function_exists调用中添加严格模式参数支持
- 更新micro_bench.php中的代码格式和测试执行逻辑
- 激活之前被注释掉的性能测试用例
pull/1/head
韩天峰 7 months ago
parent 6dd8d2d6bc
commit 08635302b6
  1. 19
      examples/micro_bench.php
  2. 1
      src/Php/CompilerBase.php
  3. 8
      src/Php/FuncCallOptimizer.php

@ -16,9 +16,10 @@ function simpleudcall($n) {
function hallo2() { function hallo2() {
} }
function simpleicall($n) { function simpleicall($n)
for ($i = 0; $i < $n; $i++) {
$ret = function_exists('hallo'); for ($i = 0; $i < $n; $i++)
$ret = function_exists('hallo');
} }
class Foo { class Foo {
@ -287,14 +288,14 @@ function main()
empty_loop(N); empty_loop(N);
$t = end_test($t, 'empty_loop'); $t = end_test($t, 'empty_loop');
$overhead = $last_time; $overhead = $last_time;
// simpleucall(N); simpleucall(N);
// $t = end_test($t, 'func()', $overhead); $t = end_test($t, 'func()', $overhead);
// simpleudcall(N); simpleudcall(N);
// $t = end_test($t, 'undef_func()', $overhead); $t = end_test($t, 'undef_func()', $overhead);
simpleicall(N); simpleicall(N);
$t = end_test($t, 'int_func()', $overhead); $t = end_test($t, 'int_func()', $overhead);
// Foo::read_static(N); Foo::read_static(N);
// $t = end_test($t, '$x = self::$x', $overhead); $t = end_test($t, '$x = self::$x', $overhead);
// Foo::write_static(N); // Foo::write_static(N);
// $t = end_test($t, 'self::$x = 0', $overhead); // $t = end_test($t, 'self::$x = 0', $overhead);
// Foo::isset_static(N); // Foo::isset_static(N);

@ -763,7 +763,6 @@ class CompilerBase extends \PhpAot\Core\Translator
if (!$this->isVarExpr($expr->var)) { if (!$this->isVarExpr($expr->var)) {
$this->fatalError($expr, 'When an assignment expression serves as an rvalue, it must be an assignment of a variable'); $this->fatalError($expr, 'When an assignment expression serves as an rvalue, it must be an assignment of a variable');
} }
return $this->parseExpr($expr); return $this->parseExpr($expr);
default: default:
return $this->parseExpr($expr); return $this->parseExpr($expr);

@ -45,7 +45,13 @@ trait FuncCallOptimizer
return 'php::math::abs(' . $this->parseIdentifier($expr->args[0]->value) . ')'; return 'php::math::abs(' . $this->parseIdentifier($expr->args[0]->value) . ')';
} }
if ($name === 'function_exists') { if ($name === 'function_exists') {
return 'php::fn::function_exists(' . $this->parseIdentifier($expr->args[0]->value) . ')'; $funcName = $expr->args[0]->value;
if ($this->isScalarString($funcName)) {
$funcName = $this->getLiteralString(strtolower(trim($funcName->value, '\\')));
return 'php::fn::function_exists(' . $funcName . ', true)';
} else {
return 'php::fn::function_exists(' . $this->parseIdentifier($funcName) . ')';
}
} }
return false; return false;

Loading…
Cancel
Save