From d0d00ae437d7184fc6fc61cbf58747162c76ec6e Mon Sep 17 00:00:00 2001 From: Carl Jackson Date: Thu, 19 Jun 2014 00:40:14 -0700 Subject: [PATCH] Inline strings.IndexRune call This is worth about 4% on github.com/julienschmidt/go-http-routing-benchmark's BenchmarkGoji_GithubAll. --- web/pattern.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/pattern.go b/web/pattern.go index 0b17e64..be4ef34 100644 --- a/web/pattern.go +++ b/web/pattern.go @@ -174,9 +174,11 @@ func (s stringPattern) match(r *http.Request, c *C, dryrun bool) bool { } path = path[len(sli):] - m := strings.IndexRune(path, '/') - if m == -1 { - m = len(path) + m := 0 + for ; m < len(path); m++ { + if path[m] == '/' { + break + } } if m == 0 { // Empty strings are not matches, otherwise routes like