1
0
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:
criciss
2026-05-03 00:12:04 +08:00
parent 87a5c22f2f
commit 01b45be8d1
2 changed files with 3 additions and 12 deletions
+1 -4
View File
@@ -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
} }
+2 -8
View File
@@ -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++ {
} }
} }