Browse Source

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.
Carl Jackson 12 years ago
parent
commit
9a6729e2ea
1 changed files with 3 additions and 2 deletions
  1. +3
    -2
      web/pattern.go

+ 3
- 2
web/pattern.go View File

@ -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 {


Loading…
Cancel
Save