Skip to content

Commit 4573422

Browse files
committed
Remove redundant is_trimmable_whitespace in String builtin
1 parent 039507d commit 4573422

File tree

2 files changed

+5
-29
lines changed
  • core/engine/src/builtins

2 files changed

+5
-29
lines changed

core/engine/src/builtins/intl/number_format/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::borrow::Cow;
2-
31
use boa_gc::{Finalize, Trace};
42
use fixed_decimal::{Decimal, FloatPrecision, SignDisplay};
53
use icu_decimal::{
@@ -30,7 +28,7 @@ use crate::{
3028
NativeFunction,
3129
builtins::{
3230
BuiltInConstructor, BuiltInObject, IntrinsicObject, builder::BuiltInBuilder,
33-
options::get_option, string::is_trimmable_whitespace,
31+
options::get_option,
3432
},
3533
context::intrinsics::{Intrinsics, StandardConstructor, StandardConstructors},
3634
js_string,
@@ -825,13 +823,12 @@ fn to_intl_mathematical_value(value: &JsValue, context: &mut Context) -> JsResul
825823
pub(crate) fn js_string_to_fixed_decimal(string: &JsString) -> Option<Decimal> {
826824
// 1. Let text be ! StringToCodePoints(str).
827825
// 2. Let literal be ParseText(text, StringNumericLiteral).
828-
let Ok(string) = string.to_std_string() else {
826+
let Ok(string) = string.trim().to_std_string() else {
829827
// 3. If literal is a List of errors, return NaN.
830828
return None;
831829
};
832830
// 4. Return StringNumericValue of literal.
833-
let string = string.trim_matches(is_trimmable_whitespace);
834-
match string {
831+
match string.as_str() {
835832
"" => return Some(Decimal::from(0)),
836833
"-Infinity" | "Infinity" | "+Infinity" => return None,
837834
_ => {}
@@ -856,11 +853,10 @@ pub(crate) fn js_string_to_fixed_decimal(string: &JsString) -> Option<Decimal> {
856853
return None;
857854
}
858855
let int = BigInt::from_str_radix(string, base).ok()?;
859-
let int_str = int.to_string();
860856

861-
Cow::Owned(int_str)
857+
int.to_string()
862858
} else {
863-
Cow::Borrowed(string)
859+
string
864860
};
865861

866862
Decimal::try_from_str(&s).ok()

core/engine/src/builtins/string/mod.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,6 @@ pub(crate) enum Placement {
5757
End,
5858
}
5959

60-
/// Helper function to check if a `char` is trimmable.
61-
pub(crate) const fn is_trimmable_whitespace(c: char) -> bool {
62-
// The rust implementation of `trim` does not regard the same characters whitespace as ecma standard does
63-
//
64-
// Rust uses \p{White_Space} by default, which also includes:
65-
// `\u{0085}' (next line)
66-
// And does not include:
67-
// '\u{FEFF}' (zero width non-breaking space)
68-
// Explicit whitespace: https://tc39.es/ecma262/#sec-white-space
69-
matches!(
70-
c,
71-
'\u{0009}' | '\u{000B}' | '\u{000C}' | '\u{0020}' | '\u{00A0}' | '\u{FEFF}' |
72-
// Unicode Space_Separator category
73-
'\u{1680}' | '\u{2000}'
74-
..='\u{200A}' | '\u{202F}' | '\u{205F}' | '\u{3000}' |
75-
// Line terminators: https://tc39.es/ecma262/#sec-line-terminators
76-
'\u{000A}' | '\u{000D}' | '\u{2028}' | '\u{2029}'
77-
)
78-
}
79-
8060
/// JavaScript `String` implementation.
8161
#[derive(Debug, Clone, Copy)]
8262
pub(crate) struct String;

0 commit comments

Comments
 (0)