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.
This commit is contained in:
Junegunn Choi
2024-04-14 07:52:42 +09:00
parent a5447b8b75
commit e86b81bbf5
4 changed files with 99 additions and 34 deletions

View File

@@ -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)
}
}