Improved performance

This commit is contained in:
Eduard Urbach 2024-03-15 00:07:44 +01:00
parent 99ad93e410
commit 8f507e4430
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 9 additions and 12 deletions

View File

@ -59,11 +59,11 @@ coverage: 100.0% of statements
## Benchmarks ## Benchmarks
``` ```
BenchmarkBlog/Len1-Param0-12 200621386 5.963 ns/op 0 B/op 0 allocs/op BenchmarkBlog/Len1-Param0-12 201446469 5.956 ns/op 0 B/op 0 allocs/op
BenchmarkBlog/Len1-Param1-12 129550375 9.224 ns/op 0 B/op 0 allocs/op BenchmarkBlog/Len1-Param1-12 130212613 9.221 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/Len7-Param0-12 70562060 16.98 ns/op 0 B/op 0 allocs/op BenchmarkGitHub/Len7-Param0-12 70604431 16.97 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/Len7-Param1-12 49366180 22.56 ns/op 0 B/op 0 allocs/op BenchmarkGitHub/Len7-Param1-12 50499285 22.55 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/Len7-Param2-12 24332162 47.91 ns/op 0 B/op 0 allocs/op BenchmarkGitHub/Len7-Param2-12 25460875 46.84 ns/op 0 B/op 0 allocs/op
``` ```
## License ## License

11
Tree.go
View File

@ -136,13 +136,7 @@ begin:
offset = i offset = i
i++ i++
for { for i < uint(len(path)) {
// We reached the end.
if i == uint(len(path)) {
addParameter(node.prefix, path[offset:i])
return node.data
}
// node: /:id|/posts // node: /:id|/posts
// path: /123|/posts // path: /123|/posts
if path[i] == separator { if path[i] == separator {
@ -156,6 +150,9 @@ begin:
i++ i++
} }
addParameter(node.prefix, path[offset:i])
return node.data
} }
// node: /|*any // node: /|*any