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
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
}
+2 -8
View File
@@ -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++ {
}
}