mirror of
https://github.com/labstack/echo.git
synced 2026-05-16 09:48:24 +02:00
refactor: use the built-in max/min to simplify the code
Signed-off-by: criciss <cricis@msn.com>
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
|
||||
if w.dumped < w.limit {
|
||||
remaining := w.limit - w.dumped
|
||||
toDump := int64(n)
|
||||
if toDump > remaining {
|
||||
toDump = remaining
|
||||
}
|
||||
toDump := min(int64(n), remaining)
|
||||
w.dumpBuf.Write(b[:toDump])
|
||||
w.dumped += toDump
|
||||
}
|
||||
|
||||
@@ -558,10 +558,7 @@ func (r *DefaultRouter) insert(t kind, path string, method string, ri routeMetho
|
||||
lcpLen := 0
|
||||
|
||||
// LCP - Longest Common Prefix (https://en.wikipedia.org/wiki/LCP_array)
|
||||
maxL := prefixLen
|
||||
if searchLen < maxL {
|
||||
maxL = searchLen
|
||||
}
|
||||
maxL := min(searchLen, prefixLen)
|
||||
for ; lcpLen < maxL && search[lcpLen] == currentNode.prefix[lcpLen]; lcpLen++ {
|
||||
}
|
||||
|
||||
@@ -867,10 +864,7 @@ func (r *DefaultRouter) Route(c *Context) HandlerFunc {
|
||||
prefixLen = len(currentNode.prefix)
|
||||
|
||||
// LCP - Longest Common Prefix (https://en.wikipedia.org/wiki/LCP_array)
|
||||
lMax := prefixLen
|
||||
if searchLen < lMax {
|
||||
lMax = searchLen
|
||||
}
|
||||
lMax := min(searchLen, prefixLen)
|
||||
for ; lcpLen < lMax && search[lcpLen] == currentNode.prefix[lcpLen]; lcpLen++ {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user