mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
perf: 解析入口改用线程本地分配器,稳态免系统调用
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//! 默认编译服务:串联 `oxide_parser::parse` 与 `Compiler::compile`,
|
||||
//! parse 错误映射与 `Allocator` 构造的唯一实现源。
|
||||
//! parse 错误映射的唯一实现源。
|
||||
|
||||
use oxide_bytecode::module::CompiledModule;
|
||||
use oxide_parser::Program;
|
||||
@@ -13,22 +13,24 @@ pub struct DefaultCompilerService;
|
||||
|
||||
impl CompilerService for DefaultCompilerService {
|
||||
fn compile_script(&self, source: &str) -> Result<CompiledModule, String> {
|
||||
// 局部分配器:AST 节点经 oxc bump 分配器分配,编译完成即弃。
|
||||
let allocator = oxide_parser::Allocator::default();
|
||||
let program = parse_program(&allocator, source)?;
|
||||
// 动态路径源契约:调用方以源码域转义(`string_forge::source_escape`)
|
||||
// 形态传源,故置 source_encoded。
|
||||
Compiler::new().with_source_encoded(true).compile(&program)
|
||||
// 线程本地分配器:AST 节点经 oxc bump 分配器分配,编译完成即弃。
|
||||
oxide_parser::with_parse_allocator(|allocator| {
|
||||
let program = parse_program(allocator, source)?;
|
||||
// 动态路径源契约:调用方以源码域转义(`string_forge::source_escape`)
|
||||
// 形态传源,故置 source_encoded。
|
||||
Compiler::new().with_source_encoded(true).compile(&program)
|
||||
})
|
||||
}
|
||||
|
||||
fn compile_eval_script(&self, source: &str) -> Result<CompiledModule, String> {
|
||||
let allocator = oxide_parser::Allocator::default();
|
||||
let program = parse_program(&allocator, source)?;
|
||||
// eval 脚本:顶层 var/function 声明落全局属性 configurable:true。
|
||||
Compiler::new()
|
||||
.with_eval_script(true)
|
||||
.with_source_encoded(true)
|
||||
.compile(&program)
|
||||
oxide_parser::with_parse_allocator(|allocator| {
|
||||
let program = parse_program(allocator, source)?;
|
||||
// eval 脚本:顶层 var/function 声明落全局属性 configurable:true。
|
||||
Compiler::new()
|
||||
.with_eval_script(true)
|
||||
.with_source_encoded(true)
|
||||
.compile(&program)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user