Compare commits
10 Commits
321e203778
...
v2.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b7e689892 | |||
| 22d13bdf7d | |||
| 3fc9a61afe | |||
| b9d1077425 | |||
| 3cd6d5d4af | |||
| a00af69b56 | |||
| c6ee27fa7a | |||
| 5c4a444231 | |||
| 452117db63 | |||
| 5da4ea66b1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
*.ez
|
*.ez
|
||||||
/build
|
/build
|
||||||
erl_crash.dump
|
erl_crash.dump
|
||||||
|
node_modules
|
||||||
|
|||||||
@@ -16,3 +16,9 @@
|
|||||||
## v2.0.2
|
## v2.0.2
|
||||||
|
|
||||||
- Minor performance improvement for uris with userinfo
|
- Minor performance improvement for uris with userinfo
|
||||||
|
- More performance improvements for ascii/digit parsing
|
||||||
|
|
||||||
|
## 2.0.3
|
||||||
|
|
||||||
|
- Minor performance improvement for erlang
|
||||||
|
- Major performance improvement for js
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name = "gluri"
|
name = "gluri"
|
||||||
version = "2.0.1"
|
version = "2.0.3"
|
||||||
|
|
||||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||||
# your project to the Hex package manager.
|
# your project to the Hex package manager.
|
||||||
|
|||||||
18
package-lock.json
generated
Normal file
18
package-lock.json
generated
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "uri",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"dependencies": {
|
||||||
|
"mitata": "^1.0.34"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mitata": {
|
||||||
|
"version": "1.0.34",
|
||||||
|
"resolved": "https://registry.npmjs.org/mitata/-/mitata-1.0.34.tgz",
|
||||||
|
"integrity": "sha512-Mc3zrtNBKIMeHSCQ0XqRLo1vbdIx1wvFV9c8NJAiyho6AjNfMY8bVhbS12bwciUdd1t4rj8099CH3N3NFahaUA==",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
package.json
Normal file
6
package.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"mitata": "^1.0.34"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import gleam/bool
|
|
||||||
import gleam/int
|
import gleam/int
|
||||||
import gleam/list
|
import gleam/list
|
||||||
import gleam/option.{type Option, None, Some}
|
import gleam/option.{type Option, None, Some}
|
||||||
@@ -181,8 +180,10 @@ fn parse_authority_part(str: String) -> Result(#(Uri, String), Nil) {
|
|||||||
|
|
||||||
// userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
|
// userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
|
||||||
fn parse_userinfo(str: String) -> #(Option(String), String) {
|
fn parse_userinfo(str: String) -> #(Option(String), String) {
|
||||||
use <- bool.guard(when: !string.contains(str, "@"), return: #(None, str))
|
case string.contains(str, "@") {
|
||||||
do_parse_userinfo(str, "")
|
True -> do_parse_userinfo(str, "")
|
||||||
|
False -> #(None, str)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_parse_userinfo(str: String, userinfo: String) -> #(Option(String), String) {
|
fn do_parse_userinfo(str: String, userinfo: String) -> #(Option(String), String) {
|
||||||
@@ -726,51 +727,112 @@ fn parse_unreserved(str: String) -> Result(#(String, String), Nil) {
|
|||||||
|
|
||||||
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||||
// / "*" / "+" / "," / ";" / "="
|
// / "*" / "+" / "," / ";" / "="
|
||||||
fn parse_sub_delim(str: String) {
|
// %21 / %24 / %26 / %27 / %28 / %29
|
||||||
|
// / %2A / %2B / %2C / %3B / %3D
|
||||||
|
@target(erlang)
|
||||||
|
fn parse_sub_delim(str: String) -> Result(#(String, String), Nil) {
|
||||||
|
case string.pop_grapheme(str) {
|
||||||
|
Ok(#("!" as char, tail))
|
||||||
|
| Ok(#("$" as char, tail))
|
||||||
|
| Ok(#("&" as char, tail))
|
||||||
|
| Ok(#("'" as char, tail))
|
||||||
|
| Ok(#("(" as char, tail))
|
||||||
|
| Ok(#(")" as char, tail))
|
||||||
|
| Ok(#("*" as char, tail))
|
||||||
|
| Ok(#("+" as char, tail))
|
||||||
|
| Ok(#("," as char, tail))
|
||||||
|
| Ok(#(";" as char, tail))
|
||||||
|
| Ok(#("=" as char, tail)) -> Ok(#(char, tail))
|
||||||
|
_ -> Error(Nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@target(javascript)
|
||||||
|
fn parse_sub_delim(str: String) -> Result(#(String, String), Nil) {
|
||||||
case str {
|
case str {
|
||||||
"!" as l <> rest
|
"!" as char <> tail
|
||||||
| "$" as l <> rest
|
| "$" as char <> tail
|
||||||
| "&" as l <> rest
|
| "&" as char <> tail
|
||||||
| "'" as l <> rest
|
| "'" as char <> tail
|
||||||
| "(" as l <> rest
|
| "(" as char <> tail
|
||||||
| ")" as l <> rest
|
| ")" as char <> tail
|
||||||
| "*" as l <> rest
|
| "*" as char <> tail
|
||||||
| "+" as l <> rest
|
| "+" as char <> tail
|
||||||
| "," as l <> rest
|
| "," as char <> tail
|
||||||
| ";" as l <> rest
|
| ";" as char <> tail
|
||||||
| "=" as l <> rest -> Ok(#(l, rest))
|
| "=" as char <> tail -> Ok(#(char, tail))
|
||||||
_ -> Error(Nil)
|
_ -> Error(Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DIGIT = %x30–39
|
// DIGIT = %x30–39
|
||||||
|
@target(erlang)
|
||||||
fn parse_digit(str: String) -> Result(#(String, String), Nil) {
|
fn parse_digit(str: String) -> Result(#(String, String), Nil) {
|
||||||
case str {
|
case string.pop_grapheme(str) {
|
||||||
"0" as l <> rest
|
Ok(#("0" as char, tail))
|
||||||
| "1" as l <> rest
|
| Ok(#("1" as char, tail))
|
||||||
| "2" as l <> rest
|
| Ok(#("2" as char, tail))
|
||||||
| "3" as l <> rest
|
| Ok(#("3" as char, tail))
|
||||||
| "4" as l <> rest
|
| Ok(#("4" as char, tail))
|
||||||
| "5" as l <> rest
|
| Ok(#("5" as char, tail))
|
||||||
| "6" as l <> rest
|
| Ok(#("6" as char, tail))
|
||||||
| "7" as l <> rest
|
| Ok(#("7" as char, tail))
|
||||||
| "8" as l <> rest
|
| Ok(#("8" as char, tail))
|
||||||
| "9" as l <> rest -> Ok(#(l, rest))
|
| Ok(#("9" as char, tail)) -> Ok(#(char, tail))
|
||||||
|
|
||||||
_ -> Error(Nil)
|
_ -> Error(Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@target(javascript)
|
||||||
|
fn parse_digit(str: String) -> Result(#(String, String), Nil) {
|
||||||
|
case str {
|
||||||
|
"0" as char <> tail
|
||||||
|
| "1" as char <> tail
|
||||||
|
| "2" as char <> tail
|
||||||
|
| "3" as char <> tail
|
||||||
|
| "4" as char <> tail
|
||||||
|
| "5" as char <> tail
|
||||||
|
| "6" as char <> tail
|
||||||
|
| "7" as char <> tail
|
||||||
|
| "8" as char <> tail
|
||||||
|
| "9" as char <> tail -> Ok(#(char, tail))
|
||||||
|
|
||||||
|
_ -> Error(Nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DIGIT (non-zero) = %x31–39
|
||||||
|
@target(erlang)
|
||||||
|
fn parse_digit_nz(str: String) -> Result(#(String, String), Nil) {
|
||||||
|
case string.pop_grapheme(str) {
|
||||||
|
Ok(#("1" as char, tail))
|
||||||
|
| Ok(#("2" as char, tail))
|
||||||
|
| Ok(#("3" as char, tail))
|
||||||
|
| Ok(#("4" as char, tail))
|
||||||
|
| Ok(#("5" as char, tail))
|
||||||
|
| Ok(#("6" as char, tail))
|
||||||
|
| Ok(#("7" as char, tail))
|
||||||
|
| Ok(#("8" as char, tail))
|
||||||
|
| Ok(#("9" as char, tail)) -> Ok(#(char, tail))
|
||||||
|
|
||||||
|
_ -> Error(Nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@target(javascript)
|
||||||
fn parse_digit_nz(str: String) -> Result(#(String, String), Nil) {
|
fn parse_digit_nz(str: String) -> Result(#(String, String), Nil) {
|
||||||
case str {
|
case str {
|
||||||
"1" as l <> rest
|
"1" as char <> tail
|
||||||
| "2" as l <> rest
|
| "2" as char <> tail
|
||||||
| "3" as l <> rest
|
| "3" as char <> tail
|
||||||
| "4" as l <> rest
|
| "4" as char <> tail
|
||||||
| "5" as l <> rest
|
| "5" as char <> tail
|
||||||
| "6" as l <> rest
|
| "6" as char <> tail
|
||||||
| "7" as l <> rest
|
| "7" as char <> tail
|
||||||
| "8" as l <> rest
|
| "8" as char <> tail
|
||||||
| "9" as l <> rest -> Ok(#(l, rest))
|
| "9" as char <> tail -> Ok(#(char, tail))
|
||||||
|
|
||||||
_ -> Error(Nil)
|
_ -> Error(Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -785,60 +847,122 @@ fn parse_digits(str: String, digits: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ALPHA = %x41–5A | %x61–7A
|
// ALPHA = %x41–5A | %x61–7A
|
||||||
|
@target(erlang)
|
||||||
|
fn parse_alpha(str: String) -> Result(#(String, String), Nil) {
|
||||||
|
case string.pop_grapheme(str) {
|
||||||
|
Ok(#("a" as char, tail))
|
||||||
|
| Ok(#("b" as char, tail))
|
||||||
|
| Ok(#("c" as char, tail))
|
||||||
|
| Ok(#("d" as char, tail))
|
||||||
|
| Ok(#("e" as char, tail))
|
||||||
|
| Ok(#("f" as char, tail))
|
||||||
|
| Ok(#("g" as char, tail))
|
||||||
|
| Ok(#("h" as char, tail))
|
||||||
|
| Ok(#("i" as char, tail))
|
||||||
|
| Ok(#("j" as char, tail))
|
||||||
|
| Ok(#("k" as char, tail))
|
||||||
|
| Ok(#("l" as char, tail))
|
||||||
|
| Ok(#("m" as char, tail))
|
||||||
|
| Ok(#("n" as char, tail))
|
||||||
|
| Ok(#("o" as char, tail))
|
||||||
|
| Ok(#("p" as char, tail))
|
||||||
|
| Ok(#("q" as char, tail))
|
||||||
|
| Ok(#("r" as char, tail))
|
||||||
|
| Ok(#("s" as char, tail))
|
||||||
|
| Ok(#("t" as char, tail))
|
||||||
|
| Ok(#("u" as char, tail))
|
||||||
|
| Ok(#("v" as char, tail))
|
||||||
|
| Ok(#("w" as char, tail))
|
||||||
|
| Ok(#("x" as char, tail))
|
||||||
|
| Ok(#("y" as char, tail))
|
||||||
|
| Ok(#("z" as char, tail))
|
||||||
|
| Ok(#("A" as char, tail))
|
||||||
|
| Ok(#("B" as char, tail))
|
||||||
|
| Ok(#("C" as char, tail))
|
||||||
|
| Ok(#("D" as char, tail))
|
||||||
|
| Ok(#("E" as char, tail))
|
||||||
|
| Ok(#("F" as char, tail))
|
||||||
|
| Ok(#("G" as char, tail))
|
||||||
|
| Ok(#("H" as char, tail))
|
||||||
|
| Ok(#("I" as char, tail))
|
||||||
|
| Ok(#("J" as char, tail))
|
||||||
|
| Ok(#("K" as char, tail))
|
||||||
|
| Ok(#("L" as char, tail))
|
||||||
|
| Ok(#("M" as char, tail))
|
||||||
|
| Ok(#("N" as char, tail))
|
||||||
|
| Ok(#("O" as char, tail))
|
||||||
|
| Ok(#("P" as char, tail))
|
||||||
|
| Ok(#("Q" as char, tail))
|
||||||
|
| Ok(#("R" as char, tail))
|
||||||
|
| Ok(#("S" as char, tail))
|
||||||
|
| Ok(#("T" as char, tail))
|
||||||
|
| Ok(#("U" as char, tail))
|
||||||
|
| Ok(#("V" as char, tail))
|
||||||
|
| Ok(#("W" as char, tail))
|
||||||
|
| Ok(#("X" as char, tail))
|
||||||
|
| Ok(#("Y" as char, tail))
|
||||||
|
| Ok(#("Z" as char, tail)) -> Ok(#(char, tail))
|
||||||
|
|
||||||
|
_ -> Error(Nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@target(javascript)
|
||||||
fn parse_alpha(str: String) -> Result(#(String, String), Nil) {
|
fn parse_alpha(str: String) -> Result(#(String, String), Nil) {
|
||||||
case str {
|
case str {
|
||||||
"a" as l <> rest
|
"a" as char <> tail
|
||||||
| "b" as l <> rest
|
| "b" as char <> tail
|
||||||
| "c" as l <> rest
|
| "c" as char <> tail
|
||||||
| "d" as l <> rest
|
| "d" as char <> tail
|
||||||
| "e" as l <> rest
|
| "e" as char <> tail
|
||||||
| "f" as l <> rest
|
| "f" as char <> tail
|
||||||
| "g" as l <> rest
|
| "g" as char <> tail
|
||||||
| "h" as l <> rest
|
| "h" as char <> tail
|
||||||
| "i" as l <> rest
|
| "i" as char <> tail
|
||||||
| "j" as l <> rest
|
| "j" as char <> tail
|
||||||
| "k" as l <> rest
|
| "k" as char <> tail
|
||||||
| "l" as l <> rest
|
| "l" as char <> tail
|
||||||
| "m" as l <> rest
|
| "m" as char <> tail
|
||||||
| "n" as l <> rest
|
| "n" as char <> tail
|
||||||
| "o" as l <> rest
|
| "o" as char <> tail
|
||||||
| "p" as l <> rest
|
| "p" as char <> tail
|
||||||
| "q" as l <> rest
|
| "q" as char <> tail
|
||||||
| "r" as l <> rest
|
| "r" as char <> tail
|
||||||
| "s" as l <> rest
|
| "s" as char <> tail
|
||||||
| "t" as l <> rest
|
| "t" as char <> tail
|
||||||
| "u" as l <> rest
|
| "u" as char <> tail
|
||||||
| "v" as l <> rest
|
| "v" as char <> tail
|
||||||
| "w" as l <> rest
|
| "w" as char <> tail
|
||||||
| "x" as l <> rest
|
| "x" as char <> tail
|
||||||
| "y" as l <> rest
|
| "y" as char <> tail
|
||||||
| "z" as l <> rest
|
| "z" as char <> tail
|
||||||
| "A" as l <> rest
|
| "A" as char <> tail
|
||||||
| "B" as l <> rest
|
| "B" as char <> tail
|
||||||
| "C" as l <> rest
|
| "C" as char <> tail
|
||||||
| "D" as l <> rest
|
| "D" as char <> tail
|
||||||
| "E" as l <> rest
|
| "E" as char <> tail
|
||||||
| "F" as l <> rest
|
| "F" as char <> tail
|
||||||
| "G" as l <> rest
|
| "G" as char <> tail
|
||||||
| "H" as l <> rest
|
| "H" as char <> tail
|
||||||
| "I" as l <> rest
|
| "I" as char <> tail
|
||||||
| "J" as l <> rest
|
| "J" as char <> tail
|
||||||
| "K" as l <> rest
|
| "K" as char <> tail
|
||||||
| "L" as l <> rest
|
| "L" as char <> tail
|
||||||
| "M" as l <> rest
|
| "M" as char <> tail
|
||||||
| "N" as l <> rest
|
| "N" as char <> tail
|
||||||
| "O" as l <> rest
|
| "O" as char <> tail
|
||||||
| "P" as l <> rest
|
| "P" as char <> tail
|
||||||
| "Q" as l <> rest
|
| "Q" as char <> tail
|
||||||
| "R" as l <> rest
|
| "R" as char <> tail
|
||||||
| "S" as l <> rest
|
| "S" as char <> tail
|
||||||
| "T" as l <> rest
|
| "T" as char <> tail
|
||||||
| "U" as l <> rest
|
| "U" as char <> tail
|
||||||
| "V" as l <> rest
|
| "V" as char <> tail
|
||||||
| "W" as l <> rest
|
| "W" as char <> tail
|
||||||
| "X" as l <> rest
|
| "X" as char <> tail
|
||||||
| "Y" as l <> rest
|
| "Y" as char <> tail
|
||||||
| "Z" as l <> rest -> Ok(#(l, rest))
|
| "Z" as char <> tail -> Ok(#(char, tail))
|
||||||
|
|
||||||
_ -> Error(Nil)
|
_ -> Error(Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,30 +370,62 @@ fn unescape_percent(str: String) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_hex_digit(str) {
|
@target(erlang)
|
||||||
|
pub fn parse_hex_digit(str: String) -> Result(#(String, String), Nil) {
|
||||||
|
case string.pop_grapheme(str) {
|
||||||
|
Ok(#("0" as char, tail))
|
||||||
|
| Ok(#("1" as char, tail))
|
||||||
|
| Ok(#("2" as char, tail))
|
||||||
|
| Ok(#("3" as char, tail))
|
||||||
|
| Ok(#("4" as char, tail))
|
||||||
|
| Ok(#("5" as char, tail))
|
||||||
|
| Ok(#("6" as char, tail))
|
||||||
|
| Ok(#("7" as char, tail))
|
||||||
|
| Ok(#("8" as char, tail))
|
||||||
|
| Ok(#("9" as char, tail))
|
||||||
|
| Ok(#("a" as char, tail))
|
||||||
|
| Ok(#("b" as char, tail))
|
||||||
|
| Ok(#("c" as char, tail))
|
||||||
|
| Ok(#("d" as char, tail))
|
||||||
|
| Ok(#("e" as char, tail))
|
||||||
|
| Ok(#("f" as char, tail))
|
||||||
|
| Ok(#("A" as char, tail))
|
||||||
|
| Ok(#("B" as char, tail))
|
||||||
|
| Ok(#("C" as char, tail))
|
||||||
|
| Ok(#("D" as char, tail))
|
||||||
|
| Ok(#("E" as char, tail))
|
||||||
|
| Ok(#("F" as char, tail)) -> Ok(#(char, tail))
|
||||||
|
|
||||||
|
_ -> Error(Nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@target(javascript)
|
||||||
|
pub fn parse_hex_digit(str: String) -> Result(#(String, String), Nil) {
|
||||||
case str {
|
case str {
|
||||||
"0" as l <> rest
|
"0" as char <> tail
|
||||||
| "1" as l <> rest
|
| "1" as char <> tail
|
||||||
| "2" as l <> rest
|
| "2" as char <> tail
|
||||||
| "3" as l <> rest
|
| "3" as char <> tail
|
||||||
| "4" as l <> rest
|
| "4" as char <> tail
|
||||||
| "5" as l <> rest
|
| "5" as char <> tail
|
||||||
| "6" as l <> rest
|
| "6" as char <> tail
|
||||||
| "7" as l <> rest
|
| "7" as char <> tail
|
||||||
| "8" as l <> rest
|
| "8" as char <> tail
|
||||||
| "9" as l <> rest
|
| "9" as char <> tail
|
||||||
| "a" as l <> rest
|
| "a" as char <> tail
|
||||||
| "b" as l <> rest
|
| "b" as char <> tail
|
||||||
| "c" as l <> rest
|
| "c" as char <> tail
|
||||||
| "d" as l <> rest
|
| "d" as char <> tail
|
||||||
| "e" as l <> rest
|
| "e" as char <> tail
|
||||||
| "f" as l <> rest
|
| "f" as char <> tail
|
||||||
| "A" as l <> rest
|
| "A" as char <> tail
|
||||||
| "B" as l <> rest
|
| "B" as char <> tail
|
||||||
| "C" as l <> rest
|
| "C" as char <> tail
|
||||||
| "D" as l <> rest
|
| "D" as char <> tail
|
||||||
| "E" as l <> rest
|
| "E" as char <> tail
|
||||||
| "F" as l <> rest -> Ok(#(l, rest))
|
| "F" as char <> tail -> Ok(#(char, tail))
|
||||||
|
|
||||||
_ -> Error(Nil)
|
_ -> Error(Nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import gleam/string
|
||||||
import gleam/uri as uri2
|
import gleam/uri as uri2
|
||||||
import gluri as uri
|
import gluri as uri
|
||||||
import glychee/benchmark
|
import glychee/benchmark
|
||||||
@@ -9,6 +10,7 @@ pub fn main() {
|
|||||||
configuration.set_pair(configuration.Warmup, 2)
|
configuration.set_pair(configuration.Warmup, 2)
|
||||||
configuration.set_pair(configuration.Parallel, 2)
|
configuration.set_pair(configuration.Parallel, 2)
|
||||||
|
|
||||||
|
// pop_benchmark()
|
||||||
parse_benchmark()
|
parse_benchmark()
|
||||||
// reg_name_benchmark()
|
// reg_name_benchmark()
|
||||||
// ip_benchmark()
|
// ip_benchmark()
|
||||||
@@ -82,3 +84,276 @@ pub fn parse_benchmark() {
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@target(erlang)
|
||||||
|
pub fn pop_benchmark() {
|
||||||
|
benchmark.run(
|
||||||
|
[
|
||||||
|
benchmark.Function("pop", fn(data) { fn() { pop(data, "") } }),
|
||||||
|
benchmark.Function("pop2", fn(data) { fn() { pop4(data, "") } }),
|
||||||
|
benchmark.Function("pop3", fn(data) { fn() { pop5(data, "") } }),
|
||||||
|
benchmark.Function("match", fn(data) { fn() { pop2(data, "") } }),
|
||||||
|
benchmark.Function("match_2", fn(data) { fn() { pop3(data, "") } }),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
// benchmark.Data("long", "abcdefghijklmnopqrstuvwxyz"),
|
||||||
|
benchmark.Data(
|
||||||
|
"with user",
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||||
|
),
|
||||||
|
// benchmark.Data("ipv4", "https://192.255.36.4/"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pop(input, _) {
|
||||||
|
case string.pop_grapheme(input) {
|
||||||
|
Ok(#(char, tail)) -> {
|
||||||
|
let assert [codepoint] = string.to_utf_codepoints(char)
|
||||||
|
let i = string.utf_codepoint_to_int(codepoint)
|
||||||
|
case i {
|
||||||
|
_ if i >= 0x41 && i <= 0x5A -> pop(tail, char)
|
||||||
|
_ if i >= 0x61 && i <= 0x7A -> pop(tail, char)
|
||||||
|
_ -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Error(_) -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pop2(input, _) {
|
||||||
|
case input {
|
||||||
|
"a" as j <> tail
|
||||||
|
| "b" as j <> tail
|
||||||
|
| "c" as j <> tail
|
||||||
|
| "d" as j <> tail
|
||||||
|
| "e" as j <> tail
|
||||||
|
| "f" as j <> tail
|
||||||
|
| "g" as j <> tail
|
||||||
|
| "h" as j <> tail
|
||||||
|
| "i" as j <> tail
|
||||||
|
| "j" as j <> tail
|
||||||
|
| "k" as j <> tail
|
||||||
|
| "l" as j <> tail
|
||||||
|
| "m" as j <> tail
|
||||||
|
| "n" as j <> tail
|
||||||
|
| "o" as j <> tail
|
||||||
|
| "p" as j <> tail
|
||||||
|
| "q" as j <> tail
|
||||||
|
| "r" as j <> tail
|
||||||
|
| "s" as j <> tail
|
||||||
|
| "t" as j <> tail
|
||||||
|
| "u" as j <> tail
|
||||||
|
| "v" as j <> tail
|
||||||
|
| "w" as j <> tail
|
||||||
|
| "x" as j <> tail
|
||||||
|
| "y" as j <> tail
|
||||||
|
| "z" as j <> tail
|
||||||
|
| "A" as j <> tail
|
||||||
|
| "B" as j <> tail
|
||||||
|
| "C" as j <> tail
|
||||||
|
| "D" as j <> tail
|
||||||
|
| "E" as j <> tail
|
||||||
|
| "F" as j <> tail
|
||||||
|
| "G" as j <> tail
|
||||||
|
| "H" as j <> tail
|
||||||
|
| "I" as j <> tail
|
||||||
|
| "J" as j <> tail
|
||||||
|
| "K" as j <> tail
|
||||||
|
| "L" as j <> tail
|
||||||
|
| "M" as j <> tail
|
||||||
|
| "N" as j <> tail
|
||||||
|
| "O" as j <> tail
|
||||||
|
| "P" as j <> tail
|
||||||
|
| "Q" as j <> tail
|
||||||
|
| "R" as j <> tail
|
||||||
|
| "S" as j <> tail
|
||||||
|
| "T" as j <> tail
|
||||||
|
| "U" as j <> tail
|
||||||
|
| "V" as j <> tail
|
||||||
|
| "W" as j <> tail
|
||||||
|
| "X" as j <> tail
|
||||||
|
| "Y" as j <> tail
|
||||||
|
| "Z" as j <> tail -> pop2(tail, j)
|
||||||
|
_ -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pop3(input, _) {
|
||||||
|
case input {
|
||||||
|
"a" <> tail
|
||||||
|
| "b" <> tail
|
||||||
|
| "c" <> tail
|
||||||
|
| "d" <> tail
|
||||||
|
| "e" <> tail
|
||||||
|
| "f" <> tail
|
||||||
|
| "g" <> tail
|
||||||
|
| "h" <> tail
|
||||||
|
| "i" <> tail
|
||||||
|
| "j" <> tail
|
||||||
|
| "k" <> tail
|
||||||
|
| "l" <> tail
|
||||||
|
| "m" <> tail
|
||||||
|
| "n" <> tail
|
||||||
|
| "o" <> tail
|
||||||
|
| "p" <> tail
|
||||||
|
| "q" <> tail
|
||||||
|
| "r" <> tail
|
||||||
|
| "s" <> tail
|
||||||
|
| "t" <> tail
|
||||||
|
| "u" <> tail
|
||||||
|
| "v" <> tail
|
||||||
|
| "w" <> tail
|
||||||
|
| "x" <> tail
|
||||||
|
| "y" <> tail
|
||||||
|
| "z" <> tail
|
||||||
|
| "A" <> tail
|
||||||
|
| "B" <> tail
|
||||||
|
| "C" <> tail
|
||||||
|
| "D" <> tail
|
||||||
|
| "E" <> tail
|
||||||
|
| "F" <> tail
|
||||||
|
| "G" <> tail
|
||||||
|
| "H" <> tail
|
||||||
|
| "I" <> tail
|
||||||
|
| "J" <> tail
|
||||||
|
| "K" <> tail
|
||||||
|
| "L" <> tail
|
||||||
|
| "M" <> tail
|
||||||
|
| "N" <> tail
|
||||||
|
| "O" <> tail
|
||||||
|
| "P" <> tail
|
||||||
|
| "Q" <> tail
|
||||||
|
| "R" <> tail
|
||||||
|
| "S" <> tail
|
||||||
|
| "T" <> tail
|
||||||
|
| "U" <> tail
|
||||||
|
| "V" <> tail
|
||||||
|
| "W" <> tail
|
||||||
|
| "X" <> tail
|
||||||
|
| "Y" <> tail
|
||||||
|
| "Z" <> tail -> pop3(tail, "")
|
||||||
|
_ -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pop4(input, _) {
|
||||||
|
case string.pop_grapheme(input) {
|
||||||
|
Ok(#(char, tail)) -> {
|
||||||
|
case char {
|
||||||
|
"a"
|
||||||
|
| "b"
|
||||||
|
| "c"
|
||||||
|
| "d"
|
||||||
|
| "e"
|
||||||
|
| "f"
|
||||||
|
| "g"
|
||||||
|
| "h"
|
||||||
|
| "i"
|
||||||
|
| "j"
|
||||||
|
| "k"
|
||||||
|
| "l"
|
||||||
|
| "m"
|
||||||
|
| "n"
|
||||||
|
| "o"
|
||||||
|
| "p"
|
||||||
|
| "q"
|
||||||
|
| "r"
|
||||||
|
| "s"
|
||||||
|
| "t"
|
||||||
|
| "u"
|
||||||
|
| "v"
|
||||||
|
| "w"
|
||||||
|
| "x"
|
||||||
|
| "y"
|
||||||
|
| "z"
|
||||||
|
| "A"
|
||||||
|
| "B"
|
||||||
|
| "C"
|
||||||
|
| "D"
|
||||||
|
| "E"
|
||||||
|
| "F"
|
||||||
|
| "G"
|
||||||
|
| "H"
|
||||||
|
| "I"
|
||||||
|
| "J"
|
||||||
|
| "K"
|
||||||
|
| "L"
|
||||||
|
| "M"
|
||||||
|
| "N"
|
||||||
|
| "O"
|
||||||
|
| "P"
|
||||||
|
| "Q"
|
||||||
|
| "R"
|
||||||
|
| "S"
|
||||||
|
| "T"
|
||||||
|
| "U"
|
||||||
|
| "V"
|
||||||
|
| "W"
|
||||||
|
| "X"
|
||||||
|
| "Y"
|
||||||
|
| "Z" -> pop4(tail, char)
|
||||||
|
_ -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Error(_) -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn pop5(input, _) {
|
||||||
|
case string.pop_grapheme(input) {
|
||||||
|
Ok(#("a" as char, tail))
|
||||||
|
| Ok(#("b" as char, tail))
|
||||||
|
| Ok(#("c" as char, tail))
|
||||||
|
| Ok(#("d" as char, tail))
|
||||||
|
| Ok(#("e" as char, tail))
|
||||||
|
| Ok(#("f" as char, tail))
|
||||||
|
| Ok(#("g" as char, tail))
|
||||||
|
| Ok(#("h" as char, tail))
|
||||||
|
| Ok(#("i" as char, tail))
|
||||||
|
| Ok(#("j" as char, tail))
|
||||||
|
| Ok(#("k" as char, tail))
|
||||||
|
| Ok(#("l" as char, tail))
|
||||||
|
| Ok(#("m" as char, tail))
|
||||||
|
| Ok(#("n" as char, tail))
|
||||||
|
| Ok(#("o" as char, tail))
|
||||||
|
| Ok(#("p" as char, tail))
|
||||||
|
| Ok(#("q" as char, tail))
|
||||||
|
| Ok(#("r" as char, tail))
|
||||||
|
| Ok(#("s" as char, tail))
|
||||||
|
| Ok(#("t" as char, tail))
|
||||||
|
| Ok(#("u" as char, tail))
|
||||||
|
| Ok(#("v" as char, tail))
|
||||||
|
| Ok(#("w" as char, tail))
|
||||||
|
| Ok(#("x" as char, tail))
|
||||||
|
| Ok(#("y" as char, tail))
|
||||||
|
| Ok(#("z" as char, tail))
|
||||||
|
| Ok(#("A" as char, tail))
|
||||||
|
| Ok(#("B" as char, tail))
|
||||||
|
| Ok(#("C" as char, tail))
|
||||||
|
| Ok(#("D" as char, tail))
|
||||||
|
| Ok(#("E" as char, tail))
|
||||||
|
| Ok(#("F" as char, tail))
|
||||||
|
| Ok(#("G" as char, tail))
|
||||||
|
| Ok(#("H" as char, tail))
|
||||||
|
| Ok(#("I" as char, tail))
|
||||||
|
| Ok(#("J" as char, tail))
|
||||||
|
| Ok(#("K" as char, tail))
|
||||||
|
| Ok(#("L" as char, tail))
|
||||||
|
| Ok(#("M" as char, tail))
|
||||||
|
| Ok(#("N" as char, tail))
|
||||||
|
| Ok(#("O" as char, tail))
|
||||||
|
| Ok(#("P" as char, tail))
|
||||||
|
| Ok(#("Q" as char, tail))
|
||||||
|
| Ok(#("R" as char, tail))
|
||||||
|
| Ok(#("S" as char, tail))
|
||||||
|
| Ok(#("T" as char, tail))
|
||||||
|
| Ok(#("U" as char, tail))
|
||||||
|
| Ok(#("V" as char, tail))
|
||||||
|
| Ok(#("W" as char, tail))
|
||||||
|
| Ok(#("X" as char, tail))
|
||||||
|
| Ok(#("Y" as char, tail))
|
||||||
|
| Ok(#("Z" as char, tail)) -> pop4(tail, char)
|
||||||
|
_ -> Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
16
test/benchmark.js
Normal file
16
test/benchmark.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { run, bench, boxplot, summary } from "mitata";
|
||||||
|
import { parse } from "../build/dev/javascript/gluri/gluri.mjs";
|
||||||
|
import { parse as parse2 } from "../build/dev/javascript/gleam_stdlib/gleam/uri.mjs";
|
||||||
|
|
||||||
|
bench("parse", () =>
|
||||||
|
parse(
|
||||||
|
"https://test_name:user%20$$$@github.com/gleam-lang/stdlib/issues/523#issuecomment-3288230480",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
bench("parse2", () =>
|
||||||
|
parse2(
|
||||||
|
"https://test_name:user%20$$$@github.com/gleam-lang/stdlib/issues/523#issuecomment-3288230480",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await run();
|
||||||
@@ -27,6 +27,45 @@ pub fn parse_general_tests() {
|
|||||||
),
|
),
|
||||||
))
|
))
|
||||||
}),
|
}),
|
||||||
|
it("ai gen pass", fn() {
|
||||||
|
let _ = uri.parse("https://example.com") |> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse("http://www.example.org/resource?id=123&lang=en")
|
||||||
|
|> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse("ftp://ftp.example.net/pub/files/archive.tar.gz")
|
||||||
|
|> should.be_ok
|
||||||
|
let _ = uri.parse("mailto:user+alias@example.com") |> should.be_ok
|
||||||
|
let _ = uri.parse("urn:isbn:978-3-16-148410-0") |> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse("ws://socket.example.com:8080/chat?room=42#section2")
|
||||||
|
|> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse("https://sub.domain.co.uk/path/to/resource/") |> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse("file:///C:/Windows/System32/drivers/etc/hosts")
|
||||||
|
|> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse("git+ssh://git@example.com:2222/repo.git") |> should.be_ok
|
||||||
|
let _ =
|
||||||
|
uri.parse(
|
||||||
|
"https://xn--fsqu00a.xn--0zwm56d/%E8%B7%AF%E5%BE%84?%E6%9F%A5%E8%AF%A2=%E5%80%BC#%E7%89%87%E6%AE%B5",
|
||||||
|
)
|
||||||
|
|> should.be_ok
|
||||||
|
Nil
|
||||||
|
}),
|
||||||
|
it("ai gen fail", fn() {
|
||||||
|
let _ = uri.parse("ht!tp://example.com") |> should.be_error
|
||||||
|
let _ = uri.parse("http://exa mple.com") |> should.be_error
|
||||||
|
let _ = uri.parse("://missing-scheme.com") |> should.be_error
|
||||||
|
let _ = uri.parse("http://example.com:80a/") |> should.be_error
|
||||||
|
let _ = uri.parse("http://[2001:db8::1") |> should.be_error
|
||||||
|
let _ = uri.parse("http://example.com/%ZZ") |> should.be_error
|
||||||
|
let _ = uri.parse("http://example.com?%") |> should.be_error
|
||||||
|
let _ = uri.parse("`https://example.com/invalid") |> should.be_error
|
||||||
|
let _ = uri.parse("http://example.com?foo=bar%2") |> should.be_error
|
||||||
|
let _ = uri.parse("http://example.com:12345abc/") |> should.be_error
|
||||||
|
}),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user