From d7f7c1cb8b0a4c3788453697e1d66ae78ba7a974 Mon Sep 17 00:00:00 2001 From: usfbih8u <> Date: Sun, 5 Jul 2026 23:41:15 +0200 Subject: [PATCH] buffer/search: only append to deltas when found increments in ReplaceRegex() Reduce the amount of deltas to improve performance in large buffers, with only a few matches. --- internal/buffer/search.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/buffer/search.go b/internal/buffer/search.go index 3f4f0dad3e..369232d84a 100644 --- a/internal/buffer/search.go +++ b/internal/buffer/search.go @@ -226,6 +226,7 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b deltas = append(deltas, Delta{newText, match[0], match[1]}) } } else { + prevFound := found newLine := search.ReplaceAllFunc(l, func(in []byte) []byte { found++ var result []byte @@ -237,7 +238,10 @@ func (b *Buffer) ReplaceRegex(start, end Loc, search *regexp.Regexp, replace []b } return result }) - deltas = append(deltas, Delta{newLine, Loc{0, i}, Loc{charCount, i}}) + + if prevFound < found { + deltas = append(deltas, Delta{newLine, Loc{0, i}, Loc{charCount, i}}) + } } }