mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-26 03:31:12 +08:00
perf: CallFrame 构造 this 判别位并入 bool 组省 8 字节
This commit is contained in:
@@ -381,7 +381,8 @@ impl Vm {
|
||||
callee,
|
||||
arguments_obj: JsValue::undefined(),
|
||||
construct_result_reg: construct.result_reg,
|
||||
constructed_this: construct.constructed_this,
|
||||
constructed_this: construct.constructed_this.unwrap_or(JsValue::undefined()),
|
||||
has_constructed_this: construct.constructed_this.is_some(),
|
||||
is_derived_constructor: obj.is_derived_constructor(),
|
||||
super_called: false,
|
||||
strict: sub_is_strict,
|
||||
|
||||
@@ -68,7 +68,13 @@ pub struct CallFrame {
|
||||
/// 无 mapped arguments 时为 undefined。GC 根(帧遍历期标记)。
|
||||
pub arguments_obj: JsValue,
|
||||
pub construct_result_reg: Option<u8>,
|
||||
pub constructed_this: Option<JsValue>,
|
||||
/// derived 构造器构造出的 this 值;仅当 `has_constructed_this` 为真时有效,
|
||||
/// 标志为假时该槽为 undefined。
|
||||
///
|
||||
/// 判别位并入结构体尾部 bool 组(单字节容纳四个 bool),字段本体只占
|
||||
/// 裸 JsValue 的 8 字节,帧整体比 Option 包装省 8 字节。
|
||||
pub constructed_this: JsValue,
|
||||
pub has_constructed_this: bool,
|
||||
pub is_derived_constructor: bool,
|
||||
/// derived 构造帧是否已成功调用 super()(父构造器正常返回后置位)。
|
||||
///
|
||||
@@ -91,6 +97,18 @@ pub struct CallFrame {
|
||||
pub upvalues: *const [*mut Cell],
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CallFrame;
|
||||
|
||||
/// CallFrame 尺寸钉:constructed_this 的判别位并入尾部 bool 组后,
|
||||
/// 帧固定 104 字节(Option 包装时代为 112 字节)。
|
||||
#[test]
|
||||
fn call_frame_size_pinned() {
|
||||
assert_eq!(std::mem::size_of::<CallFrame>(), 104);
|
||||
}
|
||||
}
|
||||
|
||||
/// 一次 `for-in` 迭代的游标:已收集的 key 列表与当前下标。
|
||||
///
|
||||
/// 体是堆上 `Box`:迭代器表与挂起状态盒各独占持有体,出表/状态盒释放时
|
||||
|
||||
@@ -74,7 +74,14 @@ impl Vm {
|
||||
f(RootGroup::Frames, frame.saved_new_target);
|
||||
f(RootGroup::Frames, frame.callee);
|
||||
f(RootGroup::Frames, frame.arguments_obj);
|
||||
f(RootGroup::Frames, frame.constructed_this.unwrap_or(JsValue::undefined()));
|
||||
f(
|
||||
RootGroup::Frames,
|
||||
if frame.has_constructed_this {
|
||||
frame.constructed_this
|
||||
} else {
|
||||
JsValue::undefined()
|
||||
},
|
||||
);
|
||||
}
|
||||
for &v in &self.save_stack {
|
||||
f(RootGroup::SaveStack, v);
|
||||
|
||||
Reference in New Issue
Block a user