Some code improvements (#1909)

* strings.ToLower comparison changed to strings.EqualFold.
* Rewrite switch statement with only one case as if.
This commit is contained in:
Kirill Motkov
2019-05-21 18:08:52 +03:00
committed by 田欧
parent 8ee9d959a0
commit b1d607a899
3 changed files with 4 additions and 6 deletions
+2 -2
View File
@@ -514,7 +514,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPa
ciPath = make([]byte, 0, len(path)+1) // preallocate enough memory
// Outer loop for walking the tree
for len(path) >= len(n.path) && strings.ToLower(path[:len(n.path)]) == strings.ToLower(n.path) {
for len(path) >= len(n.path) && strings.EqualFold(path[:len(n.path)], n.path) {
path = path[len(n.path):]
ciPath = append(ciPath, n.path...)
@@ -618,7 +618,7 @@ func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPa
return ciPath, true
}
if len(path)+1 == len(n.path) && n.path[len(path)] == '/' &&
strings.ToLower(path) == strings.ToLower(n.path[:len(path)]) &&
strings.EqualFold(path, n.path[:len(path)]) &&
n.handlers != nil {
return append(ciPath, n.path...), true
}