From c179ca6651327b81fca270ed11b7e3fdc598f5aa Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 14 Mar 2024 19:22:39 +0100 Subject: [PATCH] Improved performance --- README.md | 10 +++++----- Server.go | 7 +++++-- NullResponse_test.go => common_test.go | 0 3 files changed, 10 insertions(+), 7 deletions(-) rename NullResponse_test.go => common_test.go (100%) diff --git a/README.md b/README.md index 438df79..6128ca4 100644 --- a/README.md +++ b/README.md @@ -50,11 +50,11 @@ coverage: 100.0% of statements ## Benchmarks ``` -BenchmarkStatic/#00-12 34975490 33.63 ns/op 0 B/op 0 allocs/op -BenchmarkStatic/hello-12 26550235 44.20 ns/op 0 B/op 0 allocs/op -BenchmarkStatic/hello/world-12 20356144 59.08 ns/op 0 B/op 0 allocs/op -BenchmarkGitHub/gists/:id-12 21693214 54.80 ns/op 0 B/op 0 allocs/op -BenchmarkGitHub/repos/:a/:b-12 18118347 65.33 ns/op 0 B/op 0 allocs/op +BenchmarkStatic/#00-12 36761953 31.12 ns/op 0 B/op 0 allocs/op +BenchmarkStatic/hello-12 28145253 41.21 ns/op 0 B/op 0 allocs/op +BenchmarkStatic/hello/world-12 21206058 55.10 ns/op 0 B/op 0 allocs/op +BenchmarkGitHub/gists/:id-12 21452644 52.65 ns/op 0 B/op 0 allocs/op +BenchmarkGitHub/repos/:a/:b-12 17888092 61.59 ns/op 0 B/op 0 allocs/op ``` ## License diff --git a/Server.go b/Server.go index 64e85d2..edf704b 100644 --- a/Server.go +++ b/Server.go @@ -41,10 +41,13 @@ func New() Server { config: defaultConfig(), handlers: []Handler{ func(c Context) error { - handler := c.(*ctx).server.router.LookupNoAlloc(c.Method(), c.Path(), c.(*ctx).addParameter) + ctx := c.(*ctx) + method := ctx.Method() + path := ctx.Path() + handler := ctx.server.router.LookupNoAlloc(method, path, ctx.addParameter) if handler == nil { - return c.Status(http.StatusNotFound).String(http.StatusText(http.StatusNotFound)) + return ctx.Status(http.StatusNotFound).String(http.StatusText(http.StatusNotFound)) } return handler(c) diff --git a/NullResponse_test.go b/common_test.go similarity index 100% rename from NullResponse_test.go rename to common_test.go