mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 19:21:11 +08:00
perf: f64 转字符串去中间分配并加整数 double 快路径
This commit is contained in:
@@ -302,7 +302,7 @@ fn jsvalue_to_json<H: VmHost>(
|
||||
if !n.is_finite() {
|
||||
out.push_str("null");
|
||||
} else {
|
||||
out.push_str(&oxide_runtime_api::js_number_to_string(n));
|
||||
oxide_runtime_api::write_number_into(n, out);
|
||||
}
|
||||
} else if val.is_string() {
|
||||
let s = unsafe { (*val.as_string_ptr()).to_owned_string() };
|
||||
|
||||
@@ -181,7 +181,7 @@ pub fn number_to_string<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
};
|
||||
|
||||
if radix == 10 {
|
||||
return NativeResult::Ok(vm.new_string(&oxide_runtime_api::js_number_to_string(n)));
|
||||
return NativeResult::Ok(vm.new_string_owned(oxide_runtime_api::js_number_to_string(n)));
|
||||
}
|
||||
|
||||
if n.is_nan() {
|
||||
@@ -192,7 +192,7 @@ pub fn number_to_string<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
}
|
||||
if n.abs() >= u128::MAX as f64 {
|
||||
// 超出 u128 可精确表示的整数范围,退化为十进制近似。
|
||||
return NativeResult::Ok(vm.new_string(&oxide_runtime_api::js_number_to_string(n)));
|
||||
return NativeResult::Ok(vm.new_string_owned(oxide_runtime_api::js_number_to_string(n)));
|
||||
}
|
||||
let neg = n.is_sign_negative();
|
||||
let mut value = n.abs().trunc() as u128;
|
||||
|
||||
Reference in New Issue
Block a user