Skip to content

Commit e91d315

Browse files
author
Josh Bleecher Snyder
committed
Don't copy regexp.Regexp during range
Regexps have a sync.Mutex field, which is not safe to copy. Future versions of go vet will likely flag this (golang.org/issue/8356). This also allows the Regexp to re-use its machine during benchmarking, to nice effect: benchmark old ns/op new ns/op delta BenchmarkRegExpLoop 721637 192566 -73.32%
1 parent f253ff8 commit e91d315

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

rest/router_benchmark_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func BenchmarkRegExpLoop(b *testing.B) {
109109
if err != nil {
110110
panic(err)
111111
}
112-
routeRegexps := []regexp.Regexp{}
112+
routeRegexps := []*regexp.Regexp{}
113113
for _, route := range routes {
114114

115115
// generate the regexp string
@@ -123,7 +123,7 @@ func BenchmarkRegExpLoop(b *testing.B) {
123123
panic(err)
124124
}
125125

126-
routeRegexps = append(routeRegexps, *reg)
126+
routeRegexps = append(routeRegexps, reg)
127127
}
128128

129129
b.StartTimer()

0 commit comments

Comments
 (0)