Skip to content

Commit 7be04e6

Browse files
Dean KarnDean Karn
authored andcommitted
Merge branch 'map-vs-switch'
2 parents a836724 + 46fa8cd commit 7be04e6

File tree

5 files changed

+72
-279
lines changed

5 files changed

+72
-279
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
##Pure
22
<img align="right" src="https://raw.githubusercontent.com/go-playground/pure/master/logo.png">
3-
![Project status](https://img.shields.io/badge/version-2.3.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-2.4.0-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/pure/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/pure)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pure/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pure?branch=master)
66
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/pure)](https://goreportcard.com/report/github.com/go-playground/pure)
@@ -25,8 +25,8 @@ Installation
2525

2626
Use go get
2727

28-
```go
29-
go get github.com/go-playground/pure
28+
```shell
29+
go get -u github.com/go-playground/pure
3030
```
3131

3232
Usage
@@ -155,33 +155,33 @@ the slowdown is with the use of the `context` package, as you can see when no pa
155155
```go
156156
go test -bench=. -benchmem=true
157157
#GithubAPI Routes: 203
158-
Pure: 37816 Bytes
158+
Pure: 37560 Bytes
159159

160160
#GPlusAPI Routes: 13
161-
Pure: 3144 Bytes
161+
Pure: 2808 Bytes
162162

163163
#ParseAPI Routes: 26
164-
Pure: 5328 Bytes
164+
Pure: 5072 Bytes
165165

166166
#Static Routes: 157
167-
Pure: 21720 Bytes
168-
169-
BenchmarkPure_Param 10000000 210 ns/op 288 B/op 2 allocs/op
170-
BenchmarkPure_Param5 5000000 252 ns/op 288 B/op 2 allocs/op
171-
BenchmarkPure_Param20 5000000 384 ns/op 288 B/op 2 allocs/op
172-
BenchmarkPure_ParamWrite 5000000 266 ns/op 288 B/op 2 allocs/op
173-
BenchmarkPure_GithubStatic 20000000 70.5 ns/op 0 B/op 0 allocs/op
174-
BenchmarkPure_GithubParam 5000000 289 ns/op 288 B/op 2 allocs/op
175-
BenchmarkPure_GithubAll 30000 51338 ns/op 48098 B/op 334 allocs/op
176-
BenchmarkPure_GPlusStatic 30000000 53.5 ns/op 0 B/op 0 allocs/op
177-
BenchmarkPure_GPlusParam 10000000 236 ns/op 288 B/op 2 allocs/op
178-
BenchmarkPure_GPlus2Params 5000000 252 ns/op 288 B/op 2 allocs/op
179-
BenchmarkPure_GPlusAll 500000 2842 ns/op 3168 B/op 22 allocs/op
180-
BenchmarkPure_ParseStatic 30000000 53.1 ns/op 0 B/op 0 allocs/op
181-
BenchmarkPure_ParseParam 10000000 209 ns/op 288 B/op 2 allocs/op
182-
BenchmarkPure_Parse2Params 10000000 222 ns/op 288 B/op 2 allocs/op
183-
BenchmarkPure_ParseAll 300000 4355 ns/op 4608 B/op 32 allocs/op
184-
BenchmarkPure_StaticAll 100000 15090 ns/op 0 B/op 0 allocs/op
167+
Pure: 21224 Bytes
168+
169+
BenchmarkPure_Param 10000000 157 ns/op 240 B/op 1 allocs/op
170+
BenchmarkPure_Param5 10000000 208 ns/op 240 B/op 1 allocs/op
171+
BenchmarkPure_Param20 5000000 350 ns/op 240 B/op 1 allocs/op
172+
BenchmarkPure_ParamWrite 10000000 221 ns/op 240 B/op 1 allocs/op
173+
BenchmarkPure_GithubStatic 20000000 72.6 ns/op 0 B/op 0 allocs/op
174+
BenchmarkPure_GithubParam 10000000 230 ns/op 240 B/op 1 allocs/op
175+
BenchmarkPure_GithubAll 30000 43054 ns/op 40082 B/op 167 allocs/op
176+
BenchmarkPure_GPlusStatic 30000000 54.0 ns/op 0 B/op 0 allocs/op
177+
BenchmarkPure_GPlusParam 10000000 182 ns/op 240 B/op 1 allocs/op
178+
BenchmarkPure_GPlus2Params 10000000 207 ns/op 240 B/op 1 allocs/op
179+
BenchmarkPure_GPlusAll 1000000 2297 ns/op 2640 B/op 11 allocs/op
180+
BenchmarkPure_ParseStatic 30000000 56.2 ns/op 0 B/op 0 allocs/op
181+
BenchmarkPure_ParseParam 10000000 166 ns/op 240 B/op 1 allocs/op
182+
BenchmarkPure_Parse2Params 10000000 180 ns/op 240 B/op 1 allocs/op
183+
BenchmarkPure_ParseAll 500000 3671 ns/op 3840 B/op 16 allocs/op
184+
BenchmarkPure_StaticAll 100000 14646 ns/op 0 B/op 0 allocs/op
185185
```
186186

187187
Package Versioning

group.go

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,11 @@ func (g *routeGroup) handle(method string, path string, handler http.HandlerFunc
4848
h = g.middleware[i](h)
4949
}
5050

51-
var tree *node
52-
53-
switch method {
54-
case http.MethodGet:
55-
tree = g.pure.get
56-
case http.MethodPost:
57-
tree = g.pure.post
58-
case http.MethodHead:
59-
tree = g.pure.head
60-
case http.MethodPut:
61-
tree = g.pure.put
62-
case http.MethodDelete:
63-
tree = g.pure.del
64-
case http.MethodConnect:
65-
tree = g.pure.connect
66-
case http.MethodOptions:
67-
tree = g.pure.options
68-
case http.MethodPatch:
69-
tree = g.pure.patch
70-
case http.MethodTrace:
71-
tree = g.pure.trace
72-
default:
73-
tree = g.pure.custom[method]
74-
if tree == nil {
75-
tree = new(node)
76-
g.pure.custom[method] = tree
77-
}
51+
tree := g.pure.trees[method]
52+
53+
if tree == nil {
54+
tree = new(node)
55+
g.pure.trees[method] = tree
7856
}
7957

8058
pCount := tree.add(g.prefix+path, h)

0 commit comments

Comments
 (0)