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:
@@ -603,15 +603,31 @@ fn parse_userinfo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_scheme(str: String) -> Result(#(Uri, String), Nil) {
|
fn parse_scheme(str: String) -> Result(#(Uri, String), Nil) {
|
||||||
case parse_alpha(str) {
|
case str {
|
||||||
Ok(#(first, rest)) -> {
|
"http:" <> rest ->
|
||||||
case do_parse_scheme(rest, first) {
|
Ok(#(Uri(Some("http"), None, None, None, "", None, None), rest))
|
||||||
Error(_) -> Error(Nil)
|
"https:" <> rest ->
|
||||||
Ok(#(scheme, rest)) ->
|
Ok(#(Uri(Some("https"), None, None, None, "", None, None), rest))
|
||||||
Ok(#(Uri(Some(scheme), 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) {
|
||||||
|
Ok(#(first, rest)) -> {
|
||||||
|
case do_parse_scheme(rest, first) {
|
||||||
|
Error(_) -> Error(Nil)
|
||||||
|
Ok(#(scheme, rest)) ->
|
||||||
|
Ok(#(Uri(Some(scheme), None, None, None, "", None, None), rest))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ -> Error(Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ -> Error(Nil)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user