Skip to content

Commit

Permalink
Precompute default regexp (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Kovalov authored and erikdubbelboer committed Sep 25, 2019
1 parent be93fbd commit dc9b54d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion expvarhandler/expvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
var (
expvarHandlerCalls = expvar.NewInt("expvarHandlerCalls")
expvarRegexpErrors = expvar.NewInt("expvarRegexpErrors")

defaultRE = regexp.MustCompile(".")
)

// ExpvarHandler dumps json representation of expvars to http response.
Expand Down Expand Up @@ -52,7 +54,7 @@ func ExpvarHandler(ctx *fasthttp.RequestCtx) {
func getExpvarRegexp(ctx *fasthttp.RequestCtx) (*regexp.Regexp, error) {
r := string(ctx.QueryArgs().Peek("r"))
if len(r) == 0 {
r = "."
return defaultRE, nil
}
rr, err := regexp.Compile(r)
if err != nil {
Expand Down

0 comments on commit dc9b54d

Please sign in to comment.