mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-03 21:52:00 -07:00
Avoid unconditionally storsing input as runes
When --with-nth is used, fzf used to preprocess each line and store the result as rune array, which was wasteful if the line only contains ascii characters.
This commit is contained in:
14
src/core.go
14
src/core.go
@@ -63,9 +63,6 @@ func Run(opts *Options, revision string) {
|
||||
ansiProcessor := func(data []byte) (util.Chars, *[]ansiOffset) {
|
||||
return util.ToChars(data), nil
|
||||
}
|
||||
ansiProcessorRunes := func(data []rune) (util.Chars, *[]ansiOffset) {
|
||||
return util.RunesToChars(data), nil
|
||||
}
|
||||
if opts.Ansi {
|
||||
if opts.Theme != nil {
|
||||
var state *ansiState
|
||||
@@ -82,9 +79,6 @@ func Run(opts *Options, revision string) {
|
||||
return util.RunesToChars([]rune(trimmed)), nil
|
||||
}
|
||||
}
|
||||
ansiProcessorRunes = func(data []rune) (util.Chars, *[]ansiOffset) {
|
||||
return ansiProcessor([]byte(string(data)))
|
||||
}
|
||||
}
|
||||
|
||||
// Chunk list
|
||||
@@ -103,15 +97,15 @@ func Run(opts *Options, revision string) {
|
||||
})
|
||||
} else {
|
||||
chunkList = NewChunkList(func(data []byte, index int) Item {
|
||||
tokens := Tokenize(util.ToChars(data), opts.Delimiter)
|
||||
tokens := Tokenize(string(data), opts.Delimiter)
|
||||
trans := Transform(tokens, opts.WithNth)
|
||||
transformed := joinTokens(trans)
|
||||
if len(header) < opts.HeaderLines {
|
||||
header = append(header, string(joinTokens(trans)))
|
||||
header = append(header, transformed)
|
||||
eventBox.Set(EvtHeader, header)
|
||||
return nilItem
|
||||
}
|
||||
textRunes := joinTokens(trans)
|
||||
trimmed, colors := ansiProcessorRunes(textRunes)
|
||||
trimmed, colors := ansiProcessor([]byte(transformed))
|
||||
trimmed.Index = int32(index)
|
||||
return Item{text: trimmed, colors: colors, origText: &data}
|
||||
})
|
||||
|
Reference in New Issue
Block a user