fix(compiler): 优化数组编译避免复制操作并更新依赖版本

- 在数组编译过程中添加临时变量清理机制,避免数组复制操作
- 将 phpx 依赖从 2.3.1 版本更新至 2.3.3 版本
- 更新翻译器版本号从 0.2.0 至 0.2.3
- 提升内部版本计数器从 1058 至 1060
- 添加新的数组功能测试用例
pull/1/head
韩天峰 3 months ago
parent c9d92e4581
commit 8950c6d51d
  1. 2
      composer.json
  2. 5
      src/Php/CompilerBase.php
  3. 2
      src/Php/Translator.php
  4. 20
      tests/aot/array/007.phpt
  5. 2
      version.txt

@ -7,7 +7,7 @@
"marcj/topsort": "^2.0",
"symfony/var-dumper": "^8.0",
"symfony/yaml": "^8.0",
"swoole/phpx": "~2.3.1"
"swoole/phpx": "~2.3.3"
},
"require-dev": {
"phpunit/phpunit": "^10.4",

@ -5270,6 +5270,8 @@ class CompilerBase extends \PhpAot\Core\Translator
{
$tmpVar = $this->genTmpVarName();
$this->addLocalVar($tmpVar, self::TYPE_ARRAY);
// 释放临时变量,避免修改数组产生数组复制操作
$this->context->beforeStmtLines[] = $this->getIndent() . $tmpVar . '.clean();';
$items = $node->items;
foreach ($items as $item) {
@ -5284,9 +5286,6 @@ class CompilerBase extends \PhpAot\Core\Translator
}
}
// 释放临时变量,避免修改数组产生数组复制操作
$this->context->afterStmtLines[] = $this->getIndent() . $tmpVar . '.unset();';
return $tmpVar;
}
}

@ -36,7 +36,7 @@ use Symfony\Component\Yaml\Yaml;
class Translator extends Preprocessor
{
public const string VERSION = '0.2.0';
public const string VERSION = '0.2.3';
public const string APP_NAME = 'Swoole-Compiler (AOT)';
protected string $targetName = 'app';
protected array $sourceDirs = [];

@ -0,0 +1,20 @@
--TEST--
Array 007
--FILE--
<?php
$list = [];
for ($i = 0; $i< 3; $i++) {
$keys = array_keys([$i => true]);
$list = array_merge($list, $keys);
}
var_dump($list);
?>
--EXPECT--
array(3) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
}

@ -1 +1 @@
1058
1060

Loading…
Cancel
Save