perf: 类私有名作用域容器改哈希表,点查由线性扫描改 O(1)

This commit is contained in:
2026-10-12 04:01:14 +00:00
parent 6b2bd6abb8
commit 26441edcbc
6 changed files with 34 additions and 34 deletions
Generated
+20 -20
View File
@@ -1160,7 +1160,7 @@ dependencies = [
[[package]]
name = "oxide_builtins"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"chrono",
"fast-float",
@@ -1185,7 +1185,7 @@ dependencies = [
[[package]]
name = "oxide_bytecode"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"num-bigint",
"oxide_log",
@@ -1193,7 +1193,7 @@ dependencies = [
[[package]]
name = "oxide_cfg"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_emit",
@@ -1204,7 +1204,7 @@ dependencies = [
[[package]]
name = "oxide_cli"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"ansi_term",
"bumpalo",
@@ -1228,7 +1228,7 @@ dependencies = [
[[package]]
name = "oxide_code_cache"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"lru",
"oxide_bytecode",
@@ -1237,7 +1237,7 @@ dependencies = [
[[package]]
name = "oxide_compiler"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1257,7 +1257,7 @@ dependencies = [
[[package]]
name = "oxide_dce"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1271,7 +1271,7 @@ dependencies = [
[[package]]
name = "oxide_emit"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"num-bigint",
"oxc_allocator",
@@ -1286,7 +1286,7 @@ dependencies = [
[[package]]
name = "oxide_engine"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_compiler",
@@ -1298,7 +1298,7 @@ dependencies = [
[[package]]
name = "oxide_ir"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_log",
@@ -1307,7 +1307,7 @@ dependencies = [
[[package]]
name = "oxide_kernel"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"bumpalo",
"dashmap",
@@ -1321,7 +1321,7 @@ dependencies = [
[[package]]
name = "oxide_liveness"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1333,7 +1333,7 @@ dependencies = [
[[package]]
name = "oxide_log"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"tracing",
"tracing-appender",
@@ -1342,11 +1342,11 @@ dependencies = [
[[package]]
name = "oxide_net"
version = "0.16.3"
version = "0.16.4"
[[package]]
name = "oxide_parser"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxc_allocator",
"oxc_ast",
@@ -1361,7 +1361,7 @@ dependencies = [
[[package]]
name = "oxide_regalloc"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_cfg",
@@ -1377,7 +1377,7 @@ dependencies = [
[[package]]
name = "oxide_runtime_api"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"num-bigint",
"num-traits",
@@ -1390,7 +1390,7 @@ dependencies = [
[[package]]
name = "oxide_test262"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"oxide_bytecode",
"oxide_compiler",
@@ -1410,7 +1410,7 @@ dependencies = [
[[package]]
name = "oxide_types"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"bumpalo",
"dashmap",
@@ -1423,7 +1423,7 @@ dependencies = [
[[package]]
name = "oxide_vm"
version = "0.16.3"
version = "0.16.4"
dependencies = [
"bumpalo",
"chrono",
+1 -1
View File
@@ -24,7 +24,7 @@ members = [
]
[workspace.package]
version = "0.16.3"
version = "0.16.4"
edition = "2021"
license = "MIT"
rust-version = "1.80"
+2 -4
View File
@@ -167,10 +167,8 @@ impl Emitter {
let mut stacked_names = saved_private_names.clone();
let mut stacked_kinds = saved_private_kinds.clone();
for (n, id, kind, is_static) in &private_names {
stacked_names.retain(|(en, _)| en != n);
stacked_kinds.retain(|(en, _, _, _)| en != n);
stacked_names.push((n.clone(), *id));
stacked_kinds.push((n.clone(), *kind, *is_static, private_brand_id.unwrap_or(0)));
stacked_names.insert(n.clone(), *id);
stacked_kinds.insert(n.clone(), (*kind, *is_static, private_brand_id.unwrap_or(0)));
}
ctx.scopes.private_name_map = stacked_names;
ctx.scopes.private_element_kinds = stacked_kinds;
+2 -2
View File
@@ -266,8 +266,8 @@ impl CompileCtx {
scopes: ScopeCtx {
symbols: SymbolTable::new(),
builtin_reg_map: Vec::new(),
private_name_map: Vec::new(),
private_element_kinds: Vec::new(),
private_name_map: HashMap::new(),
private_element_kinds: HashMap::new(),
private_brand_id: None,
next_private_name_id: 1,
},
+6 -3
View File
@@ -5,6 +5,8 @@
//! `PatternCtx` 为解构工作预留。执行流字段(insts/registers/pc 等)仍
//! 平铺在 `CompileCtx` 上。
use std::collections::HashMap;
use crate::symbol_table::SymbolTable;
use oxide_ir::operand::LabelId;
use oxide_parser::MethodDefinitionKind;
@@ -147,12 +149,13 @@ impl LabelCtx {
pub(crate) struct ScopeCtx {
pub(crate) symbols: SymbolTable,
pub(crate) builtin_reg_map: Vec<(String, u32)>,
pub(crate) private_name_map: Vec<(String, u32)>,
/// 私有元素类型(name, kind,static 标志,声明类 brand id)。kind=None 表示
/// 私有名 → 私有名 id。
pub(crate) private_name_map: HashMap<String, u32>,
/// 私有元素类型(kind,static 标志,声明类 brand id)。kind=None 表示
/// 字段;instance 字段的私有访问走 PrivateFieldFind 原型链查找,不加 brand
/// 检查。brand_id 是声明该私有名的类的 brand id:跨类访问时 brand 检查须
/// 定位声明类(而非访问发生处类)的 brand 对象。
pub(crate) private_element_kinds: Vec<(String, Option<MethodDefinitionKind>, bool, u32)>,
pub(crate) private_element_kinds: HashMap<String, (Option<MethodDefinitionKind>, bool, u32)>,
/// 当前类的私有 brand 私有名 id:私有方法/访问器访问时对实例做 brand 检查。
pub(crate) private_brand_id: Option<u32>,
pub(crate) next_private_name_id: u32,
+3 -4
View File
@@ -12,8 +12,8 @@ impl Emitter {
pub(crate) fn private_name_id(&self, name: &str, ctx: &CompileCtx) -> Result<u32, String> {
ctx.scopes
.private_name_map
.iter()
.find_map(|(n, id)| (n == name).then_some(*id))
.get(name)
.copied()
.ok_or_else(|| format!("private name #{name} is not defined"))
}
@@ -36,8 +36,7 @@ impl Emitter {
pub(crate) fn private_access_brand(
&self, _obj_reg: u32, name: &str, ctx: &mut CompileCtx,
) -> Result<(u32, u32), String> {
let entry = ctx.scopes.private_element_kinds.iter().find(|(n, _, _, _)| n == name);
let Some((_, kind, is_static, brand_id)) = entry else {
let Some((kind, is_static, brand_id)) = ctx.scopes.private_element_kinds.get(name) else {
return Ok((0, 0));
};
if kind.is_none() && !is_static {