Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: len() call number can be reduced #17308

tabakerov opened this issue Oct 1, 2016 · 1 comment

net/http: len() call number can be reduced #17308

tabakerov opened this issue Oct 1, 2016 · 1 comment


Copy link

@tabakerov tabakerov commented Oct 1, 2016

there is a function in server.go:

func pathMatch(pattern, path string) bool {
if len(pattern) == 0 {
    // should not happen
    return false
n := len(pattern)
if pattern[n-1] != '/' {
    return pattern == path
return len(path) >= n && path[0:n] == pattern

if assign len(pattern) to variable n at the first line and do check if n == 0 then number of calls len() will be reduced.


This comment has been minimized.

Copy link

@bradfitz bradfitz commented Oct 1, 2016

len() is not a call. It's as cheap as accessing a variable. Both "calls" will likely just be the same register access.

@bradfitz bradfitz closed this Oct 1, 2016
@golang golang locked and limited conversation to collaborators Oct 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.