From 6a4a19131849ed3734e7ed98698218809888dd6d Mon Sep 17 00:00:00 2001 From: CodeMarker Date: Fri, 6 Feb 2026 10:49:05 +0800 Subject: [PATCH] perf: Use swap deletion --- internal/agent/tools/grep_chunks.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/agent/tools/grep_chunks.go b/internal/agent/tools/grep_chunks.go index 913e3b74..c830d97f 100644 --- a/internal/agent/tools/grep_chunks.go +++ b/internal/agent/tools/grep_chunks.go @@ -687,9 +687,12 @@ func (t *GrepChunksTool) applyMMR( selected = append(selected, candidates[bestIdx]) selectedTokenSets = append(selectedTokenSets, tokenSets[bestIdx]) - candidates = append(candidates[:bestIdx], candidates[bestIdx+1:]...) - // Remove corresponding token set - tokenSets = append(tokenSets[:bestIdx], tokenSets[bestIdx+1:]...) + // Remove corresponding token set. Use swap deletion + last := len(candidates) - 1 + candidates[bestIdx] = candidates[last] + tokenSets[bestIdx] = tokenSets[last] + candidates = candidates[:last] + tokenSets = tokenSets[:last] } // Compute average redundancy among selected results