perf: Fix minor perf issue for JS

This commit is contained in:
2025-09-22 12:30:09 +01:00
parent a00af69b56
commit 3cd6d5d4af
2 changed files with 22 additions and 17 deletions

View File

@@ -733,12 +733,13 @@ fn parse_sub_delim(str: String) -> Result(#(String, String), Nil) {
case string.pop_grapheme(str) { case string.pop_grapheme(str) {
Ok(#(char, tail)) -> { Ok(#(char, tail)) -> {
let assert [codepoint] = string.to_utf_codepoints(char) let assert [codepoint] = string.to_utf_codepoints(char)
case string.utf_codepoint_to_int(codepoint) { let i = string.utf_codepoint_to_int(codepoint)
i if i >= 0x26 && i <= 0x2C -> Ok(#(char, tail)) case i {
i if i == 0x21 -> Ok(#(char, tail)) _ if i >= 0x26 && i <= 0x2C -> Ok(#(char, tail))
i if i == 0x24 -> Ok(#(char, tail)) _ if i == 0x21 -> Ok(#(char, tail))
i if i == 0x3B -> Ok(#(char, tail)) _ if i == 0x24 -> Ok(#(char, tail))
i if i == 0x3D -> Ok(#(char, tail)) _ if i == 0x3B -> Ok(#(char, tail))
_ if i == 0x3D -> Ok(#(char, tail))
_ -> Error(Nil) _ -> Error(Nil)
} }
} }
@@ -751,8 +752,9 @@ fn parse_digit(str: String) -> Result(#(String, String), Nil) {
case string.pop_grapheme(str) { case string.pop_grapheme(str) {
Ok(#(char, tail)) -> { Ok(#(char, tail)) -> {
let assert [codepoint] = string.to_utf_codepoints(char) let assert [codepoint] = string.to_utf_codepoints(char)
case string.utf_codepoint_to_int(codepoint) { let i = string.utf_codepoint_to_int(codepoint)
i if i >= 0x30 && i <= 0x39 -> Ok(#(char, tail)) case i {
_ if i >= 0x30 && i <= 0x39 -> Ok(#(char, tail))
_ -> Error(Nil) _ -> Error(Nil)
} }
} }
@@ -765,8 +767,9 @@ fn parse_digit_nz(str: String) -> Result(#(String, String), Nil) {
case string.pop_grapheme(str) { case string.pop_grapheme(str) {
Ok(#(char, tail)) -> { Ok(#(char, tail)) -> {
let assert [codepoint] = string.to_utf_codepoints(char) let assert [codepoint] = string.to_utf_codepoints(char)
case string.utf_codepoint_to_int(codepoint) { let i = string.utf_codepoint_to_int(codepoint)
i if i >= 0x31 && i <= 0x39 -> Ok(#(char, tail)) case i {
_ if i >= 0x31 && i <= 0x39 -> Ok(#(char, tail))
_ -> Error(Nil) _ -> Error(Nil)
} }
} }
@@ -788,9 +791,10 @@ fn parse_alpha(str: String) -> Result(#(String, String), Nil) {
case string.pop_grapheme(str) { case string.pop_grapheme(str) {
Ok(#(char, tail)) -> { Ok(#(char, tail)) -> {
let assert [codepoint] = string.to_utf_codepoints(char) let assert [codepoint] = string.to_utf_codepoints(char)
case string.utf_codepoint_to_int(codepoint) { let i = string.utf_codepoint_to_int(codepoint)
i if i >= 0x41 && i <= 0x5A -> Ok(#(char, tail)) case i {
i if i >= 0x61 && i <= 0x7A -> Ok(#(char, tail)) _ if i >= 0x41 && i <= 0x5A -> Ok(#(char, tail))
_ if i >= 0x61 && i <= 0x7A -> Ok(#(char, tail))
_ -> Error(Nil) _ -> Error(Nil)
} }
} }

View File

@@ -374,10 +374,11 @@ pub fn parse_hex_digit(str: String) -> Result(#(String, String), Nil) {
case string.pop_grapheme(str) { case string.pop_grapheme(str) {
Ok(#(char, tail)) -> { Ok(#(char, tail)) -> {
let assert [codepoint] = string.to_utf_codepoints(char) let assert [codepoint] = string.to_utf_codepoints(char)
case string.utf_codepoint_to_int(codepoint) { let i = string.utf_codepoint_to_int(codepoint)
i if i >= 0x30 && i <= 0x39 -> Ok(#(char, tail)) case i {
i if i >= 0x41 && i <= 0x46 -> Ok(#(char, tail)) _ if i >= 0x30 && i <= 0x39 -> Ok(#(char, tail))
i if i >= 0x61 && i <= 0x66 -> Ok(#(char, tail)) _ if i >= 0x41 && i <= 0x46 -> Ok(#(char, tail))
_ if i >= 0x61 && i <= 0x66 -> Ok(#(char, tail))
_ -> Error(Nil) _ -> Error(Nil)
} }
} }