mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-28 03:38:11 +08:00
refactor: use the built-in max/min to simplify the code (#17059)
### Summary In Go 1.21, the standard library includes built-in [max/min](https://pkg.go.dev/builtin@go1.21.0#max) function, which can greatly simplify the code. Signed-off-by: futurehua <futurehua@outlook.com>
This commit is contained in:
@@ -47,10 +47,7 @@ func layoutCleanup(cells []pdf.TSRCell, boxes []pdf.TextBox, far int, thr float6
|
||||
i := 0
|
||||
for i+1 < len(out) {
|
||||
j := i + 1
|
||||
limit := i + far
|
||||
if limit > len(out) {
|
||||
limit = len(out)
|
||||
}
|
||||
limit := min(i+far, len(out))
|
||||
for j < limit && (out[i].Label != "" && out[i].Label != out[j].Label || notOverlapped(out[i], out[j])) {
|
||||
j++
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ func FilterBoxesByRemoveSet(boxes []pdf.TextBox, removeSet map[int]bool) []pdf.T
|
||||
}
|
||||
// Pre-allocate: estimate final size to avoid resizing
|
||||
// Use max to prevent negative capacity when len(removeSet) > len(boxes)
|
||||
estimatedCap := len(boxes) - len(removeSet)
|
||||
if estimatedCap < 0 {
|
||||
estimatedCap = 0
|
||||
}
|
||||
estimatedCap := max(len(boxes)-len(removeSet), 0)
|
||||
out := make([]pdf.TextBox, 0, estimatedCap)
|
||||
for i, b := range boxes {
|
||||
if !removeSet[i] {
|
||||
|
||||
Reference in New Issue
Block a user