From 9a6729e2eab232c62592dde59966c4a238eface0 Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Thu, 19 Jun 2014 00:29:55 -0700 Subject: [PATCH] Don't look up s.literals[i] twice This is worth about 3% in github.com/julienschmidt/go-http-routing-benchmark's BenchmarkGoji_GithubAll. Not a huge win, but definitely still worth it. --- web/pattern.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/pattern.go b/web/pattern.go index 903f6fd..0b17e64 100644 --- a/web/pattern.go +++ b/web/pattern.go @@ -168,10 +168,11 @@ func (s stringPattern) match(r *http.Request, c *C, dryrun bool) bool { matches = make(map[string]string, len(s.pats)) } for i := 0; i < len(s.pats); i++ { - if !strings.HasPrefix(path, s.literals[i]) { + sli := s.literals[i] + if !strings.HasPrefix(path, sli) { return false } - path = path[len(s.literals[i]):] + path = path[len(sli):] m := strings.IndexRune(path, '/') if m == -1 {