From e86b81bbf5c55344f4e29060b71eb1ab563296fe Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 14 Apr 2024 07:52:42 +0900 Subject: Improve search performance by limiting the search scope Find the last occurrence of the last character in the pattern and perform the search algorithm only up to that point. The effectiveness of this mechanism depends a lot on the shape of the input and the pattern. --- src/util/chars.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/util') diff --git a/src/util/chars.go b/src/util/chars.go index f946da82..f84d365f 100644 --- a/src/util/chars.go +++ b/src/util/chars.go @@ -178,12 +178,12 @@ func (chars *Chars) ToRunes() []rune { return runes } -func (chars *Chars) CopyRunes(dest []rune) { +func (chars *Chars) CopyRunes(dest []rune, from int) { if runes := chars.optionalRunes(); runes != nil { - copy(dest, runes) + copy(dest, runes[from:]) return } - for idx, b := range chars.slice[:len(dest)] { + for idx, b := range chars.slice[from:][:len(dest)] { dest[idx] = rune(b) } } -- cgit v1.2.3