mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
perf: JsString 缓存 UTF-16 length,字符串 length 访问改 O(1)
This commit is contained in:
@@ -47,8 +47,8 @@ impl Vm {
|
||||
if val.is_string() {
|
||||
let length_si = self.kernel_core.perm_interner().intern("length").0;
|
||||
if prop_name_si == length_si {
|
||||
// SAFETY: val 是字符串值。
|
||||
let len = unsafe { (*val.as_string_ptr()).data.encode_utf16().count() };
|
||||
// SAFETY: val 是字符串值。utf16_len 构造时缓存,O(1) 读取。
|
||||
let len = unsafe { (*val.as_string_ptr()).utf16_len() };
|
||||
return Ok(Some(JsValue::int(len as i32)));
|
||||
}
|
||||
let proto_ptr = self.session.builtin_world().string_proto.as_ptr() as *mut JsObject;
|
||||
|
||||
Reference in New Issue
Block a user