refactor: match 可改 ? 的等价改写

This commit is contained in:
2026-08-16 14:04:25 +08:00
parent fd2b290927
commit 1a244398f1
3 changed files with 21 additions and 33 deletions
+9 -13
View File
@@ -185,21 +185,17 @@ impl ShapeForge {
let mut prop_steps: u32 = 0; let mut prop_steps: u32 = 0;
let mut cursor = Some(shape_id); let mut cursor = Some(shape_id);
while let Some(id) = cursor { while let Some(id) = cursor {
match shapes.get((id - 1) as usize).and_then(|s| s.clone()) { let s = shapes.get((id - 1) as usize).and_then(|s| s.clone())?;
Some(s) => { if s.property_name != EMPTY_SENTINEL {
if s.property_name != EMPTY_SENTINEL { if s.property_name == prop_name {
if s.property_name == prop_name { let pos = total_depth.checked_sub(prop_steps + 1)?;
let pos = total_depth.checked_sub(prop_steps + 1)?; drop(shapes);
drop(shapes); self.positions.insert(cache_key, pos);
self.positions.insert(cache_key, pos); return Some(pos);
return Some(pos);
}
prop_steps += 1;
}
cursor = s.parent;
} }
None => return None, prop_steps += 1;
} }
cursor = s.parent;
} }
None None
} }
+5 -9
View File
@@ -105,16 +105,12 @@ impl ShapeStore {
let mut step: u32 = 0; let mut step: u32 = 0;
cursor = Some(shape_id); cursor = Some(shape_id);
while let Some(id) = cursor { while let Some(id) = cursor {
match self.get_shape(id) { let s = self.get_shape(id)?;
Some(s) => { if s.property_name == prop_name && s.property_name != EMPTY_SENTINEL {
if s.property_name == prop_name && s.property_name != EMPTY_SENTINEL { return Some(total_depth - step - 1);
return Some(total_depth - step - 1);
}
cursor = s.parent;
step += 1;
}
None => return None,
} }
cursor = s.parent;
step += 1;
} }
None None
} }
+7 -11
View File
@@ -492,18 +492,14 @@ impl Vm {
NativeResult::TailCall { callee, this, args } => { NativeResult::TailCall { callee, this, args } => {
// 如 bound 函数:解析尾调用,用其返回值作为构造实例 // 如 bound 函数:解析尾调用,用其返回值作为构造实例
// (或回退到 derived_this)。 // (或回退到 derived_this)。
match self.call_function_sync(callee, this, &args) { let val = self.call_function_sync(callee, this, &args)?;
Ok(val) => { let instance = if val.is_object() { val } else { derived_this };
let instance = if val.is_object() { val } else { derived_this }; if instance.is_object() {
if instance.is_object() { self.set_constructed_proto(instance, new_target_obj)?;
self.set_constructed_proto(instance, new_target_obj)?;
}
self.regs[254] = instance;
self.regs[rd] = self.regs[254];
self.mark_super_called();
}
Err(e) => return Err(e),
} }
self.regs[254] = instance;
self.regs[rd] = self.regs[254];
self.mark_super_called();
} }
} }
} else if super_obj.sub_module_index() > 0 { } else if super_obj.sub_module_index() > 0 {