mirror of
https://github.com/labstack/echo.git
synced 2026-05-16 09:48:24 +02:00
Merge pull request #2966 from criciss/master
refactor: use the built-in max/min to simplify the code
This commit is contained in:
@@ -189,10 +189,7 @@ func (w *limitedWriter) Write(b []byte) (n int, err error) {
|
|||||||
// Write to dump buffer only up to limit
|
// Write to dump buffer only up to limit
|
||||||
if w.dumped < w.limit {
|
if w.dumped < w.limit {
|
||||||
remaining := w.limit - w.dumped
|
remaining := w.limit - w.dumped
|
||||||
toDump := int64(n)
|
toDump := min(int64(n), remaining)
|
||||||
if toDump > remaining {
|
|
||||||
toDump = remaining
|
|
||||||
}
|
|
||||||
w.dumpBuf.Write(b[:toDump])
|
w.dumpBuf.Write(b[:toDump])
|
||||||
w.dumped += toDump
|
w.dumped += toDump
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -558,10 +558,7 @@ func (r *DefaultRouter) insert(t kind, path string, method string, ri routeMetho
|
|||||||
lcpLen := 0
|
lcpLen := 0
|
||||||
|
|
||||||
// LCP - Longest Common Prefix (https://en.wikipedia.org/wiki/LCP_array)
|
// LCP - Longest Common Prefix (https://en.wikipedia.org/wiki/LCP_array)
|
||||||
maxL := prefixLen
|
maxL := min(searchLen, prefixLen)
|
||||||
if searchLen < maxL {
|
|
||||||
maxL = searchLen
|
|
||||||
}
|
|
||||||
for ; lcpLen < maxL && search[lcpLen] == currentNode.prefix[lcpLen]; lcpLen++ {
|
for ; lcpLen < maxL && search[lcpLen] == currentNode.prefix[lcpLen]; lcpLen++ {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -867,10 +864,7 @@ func (r *DefaultRouter) Route(c *Context) HandlerFunc {
|
|||||||
prefixLen = len(currentNode.prefix)
|
prefixLen = len(currentNode.prefix)
|
||||||
|
|
||||||
// LCP - Longest Common Prefix (https://en.wikipedia.org/wiki/LCP_array)
|
// LCP - Longest Common Prefix (https://en.wikipedia.org/wiki/LCP_array)
|
||||||
lMax := prefixLen
|
lMax := min(searchLen, prefixLen)
|
||||||
if searchLen < lMax {
|
|
||||||
lMax = searchLen
|
|
||||||
}
|
|
||||||
for ; lcpLen < lMax && search[lcpLen] == currentNode.prefix[lcpLen]; lcpLen++ {
|
for ; lcpLen < lMax && search[lcpLen] == currentNode.prefix[lcpLen]; lcpLen++ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user