Precompute default regexp (#662)

This commit is contained in:
Oleg Kovalov
2019-09-25 20:56:31 +02:00
committed by Erik Dubbelboer
parent be93fbd21b
commit dc9b54dbdf
+3 -1
View File
@@ -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.
@@ -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 {