Skip to content

Commit

Permalink
change order for speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
kkHAIKE committed Sep 19, 2022
1 parent 4a70670 commit 2f300bb
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions contextcheck.go
Expand Up @@ -351,19 +351,14 @@ func (r *runner) checkIsHttpHandler(f *ssa.Function, reqctx bool) bool {
return true
}

// check if use r.Context()
if f.Blocks != nil && len(r.getHttpReqCtx(f, true)) > 0 {
// must be `func f(w http.ResponseWriter, r *http.Request) {}`
if f.Signature.Results().Len() == 0 && tuple.Len() == 2 &&
r.isHttpResType(tuple.At(0).Type()) && r.isHttpReqType(tuple.At(1).Type()) {
return true
}

// must be `func f(w http.ResponseWriter, r *http.Request) {}`
if f.Signature.Results().Len() > 0 {
return false
}
if tuple.Len() != 2 {
return false
}
return r.isHttpResType(tuple.At(0).Type()) && r.isHttpReqType(tuple.At(1).Type())
// check if use r.Context()
return f.Blocks != nil && len(r.getHttpReqCtx(f, true)) > 0
}

func (r *runner) collectCtxRef(f *ssa.Function, isHttpHandler bool) (refMap map[ssa.Instruction]bool, ok bool) {
Expand Down

0 comments on commit 2f300bb

Please sign in to comment.