refactor(Php): 优化链式表达式解析逻辑

- 将函数获取操作提前到方法开始处,避免重复调用
- 统一使用预获取的函数名变量进行字符串拼接
- 移除重复的 getChainedFunc 方法调用
- 简化 isset 操作符的条件判断逻辑
- 优化代码结构以提高执行效率
pull/1/head v0.0.2
韩天峰 5 months ago
parent b7236ce38b
commit 517c0d8a83
  1. 6
      src/Php/CompilerBase.php

@ -3648,13 +3648,14 @@ class CompilerBase extends \PhpAot\Core\Translator
protected function parseChainedExpr(NodeAbstract $node, string $op, bool $getValue = false): string
{
$fn = $this->getChainedFunc($op);
$expr = $node;
if ($this->isVarExpr($expr)) {
if ($op === self::OP_ISSET) {
$var = $this->parseIdentifier($expr);
return $this->hasVar($var) ? 'php::exists(' . $var . ')' : 'false';
return $this->hasVar($var) ? $fn . '(' . $var . ')' : 'false';
}
return $this->getChainedFunc($op) . '(' . $this->parseExpr($expr) . ')';
return $fn . '(' . $this->parseExpr($expr) . ')';
}
$list = [];
@ -3681,7 +3682,6 @@ class CompilerBase extends \PhpAot\Core\Translator
}
$list = array_reverse($list);
$fn = $this->getChainedFunc($op);
if ($getValue) {
$result = $this->addTmpVar(self::TYPE_VAR);

Loading…
Cancel
Save