perf: Add tweak to parse known schema more quickly

http, https, and a few other urls can be assumed to be possible schemes.
If we check for these then we cut down on the character by character
parsing that would otherwise happen
This commit is contained in:
2025-09-14 17:11:04 +01:00
parent 4cad0c5bc3
commit 8b8d3e577e

View File

@@ -603,6 +603,20 @@ fn parse_userinfo(
} }
fn parse_scheme(str: String) -> Result(#(Uri, String), Nil) { fn parse_scheme(str: String) -> Result(#(Uri, String), Nil) {
case str {
"http:" <> rest ->
Ok(#(Uri(Some("http"), None, None, None, "", None, None), rest))
"https:" <> rest ->
Ok(#(Uri(Some("https"), None, None, None, "", None, None), rest))
"ftp:" <> rest ->
Ok(#(Uri(Some("ftp"), None, None, None, "", None, None), rest))
"file:" <> rest ->
Ok(#(Uri(Some("file"), None, None, None, "", None, None), rest))
"ws:" <> rest ->
Ok(#(Uri(Some("ws"), None, None, None, "", None, None), rest))
"wss:" <> rest ->
Ok(#(Uri(Some("wss"), None, None, None, "", None, None), rest))
_ -> {
case parse_alpha(str) { case parse_alpha(str) {
Ok(#(first, rest)) -> { Ok(#(first, rest)) -> {
case do_parse_scheme(rest, first) { case do_parse_scheme(rest, first) {
@@ -613,6 +627,8 @@ fn parse_scheme(str: String) -> Result(#(Uri, String), Nil) {
} }
_ -> Error(Nil) _ -> Error(Nil)
} }
}
}
} }
fn do_parse_scheme( fn do_parse_scheme(