mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-26 02:13:29 +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:
@@ -217,10 +217,7 @@ func (o *SplitOperator) splitByLength(text string) []ChunkData {
|
||||
chunkSize = defaultLengthChunkSize
|
||||
}
|
||||
|
||||
overlap := o.overlap
|
||||
if overlap < 0 {
|
||||
overlap = 0
|
||||
}
|
||||
overlap := max(o.overlap, 0)
|
||||
if overlap >= chunkSize {
|
||||
overlap = chunkSize - 1
|
||||
}
|
||||
@@ -233,10 +230,7 @@ func (o *SplitOperator) splitByLength(text string) []ChunkData {
|
||||
|
||||
var chunks []ChunkData
|
||||
for start := 0; start < len(runes); start += step {
|
||||
end := start + chunkSize
|
||||
if end > len(runes) {
|
||||
end = len(runes)
|
||||
}
|
||||
end := min(start+chunkSize, len(runes))
|
||||
|
||||
content := string(runes[start:end])
|
||||
chunks = append(chunks, ChunkData{
|
||||
|
||||
Reference in New Issue
Block a user