summaryrefslogtreecommitdiffstats
path: root/src/core.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-08-02 14:00:18 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-08-02 14:00:18 +0900
commit0ea66329b84cc6e4f8ff61ee99c00bb238070247 (patch)
tree72c3bc62ec491246390b56b2aac5b33645839503 /src/core.go
parent634670e3ea51a2fa1498a3de0c074b819828e2d8 (diff)
Performance tuning - eager rune array conversion
> wc -l /tmp/list2 2594098 /tmp/list2 > time cat /tmp/list2 | fzf-0.10.1-darwin_amd64 -fqwerty > /dev/null real 0m5.418s user 0m10.990s sys 0m1.302s > time cat /tmp/list2 | fzf-head -fqwerty > /dev/null real 0m4.862s user 0m6.619s sys 0m0.982s
Diffstat (limited to 'src/core.go')
-rw-r--r--src/core.go36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/core.go b/src/core.go
index 7e40bd5e..c0596e33 100644
--- a/src/core.go
+++ b/src/core.go
@@ -63,24 +63,24 @@ func Run(opts *Options) {
eventBox := util.NewEventBox()
// ANSI code processor
- ansiProcessor := func(data *string) (*string, []ansiOffset) {
+ ansiProcessor := func(runes []rune) ([]rune, []ansiOffset) {
// By default, we do nothing
- return data, nil
+ return runes, nil
}
if opts.Ansi {
if opts.Theme != nil {
var state *ansiState
- ansiProcessor = func(data *string) (*string, []ansiOffset) {
- trimmed, offsets, newState := extractColor(data, state)
+ ansiProcessor = func(runes []rune) ([]rune, []ansiOffset) {
+ trimmed, offsets, newState := extractColor(string(runes), state)
state = newState
- return trimmed, offsets
+ return []rune(trimmed), offsets
}
} else {
// When color is disabled but ansi option is given,
// we simply strip out ANSI codes from the input
- ansiProcessor = func(data *string) (*string, []ansiOffset) {
- trimmed, _, _ := extractColor(data, nil)
- return trimmed, nil
+ ansiProcessor = func(runes []rune) ([]rune, []ansiOffset) {
+ trimmed, _, _ := extractColor(string(runes), nil)
+ return []rune(trimmed), nil
}
}
}
@@ -89,9 +89,9 @@ func Run(opts *Options) {
var chunkList *ChunkList
header := make([]string, 0, opts.HeaderLines)
if len(opts.WithNth) == 0 {
- chunkList = NewChunkList(func(data *string, index int) *Item {
+ chunkList = NewChunkList(func(data []rune, index int) *Item {
if len(header) < opts.HeaderLines {
- header = append(header, *data)
+ header = append(header, string(data))
eventBox.Set(EvtHeader, header)
return nil
}
@@ -103,17 +103,17 @@ func Run(opts *Options) {
rank: Rank{0, 0, uint32(index)}}
})
} else {
- chunkList = NewChunkList(func(data *string, index int) *Item {
+ chunkList = NewChunkList(func(data []rune, index int) *Item {
tokens := Tokenize(data, opts.Delimiter)
trans := Transform(tokens, opts.WithNth)
if len(header) < opts.HeaderLines {
- header = append(header, *joinTokens(trans))
+ header = append(header, string(joinTokens(trans)))
eventBox.Set(EvtHeader, header)
return nil
}
item := Item{
text: joinTokens(trans),
- origText: data,
+ origText: &data,
index: uint32(index),
colors: nil,
rank: Rank{0, 0, uint32(index)}}
@@ -128,8 +128,8 @@ func Run(opts *Options) {
// Reader
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
if !streamingFilter {
- reader := Reader{func(str string) bool {
- return chunkList.Push(str)
+ reader := Reader{func(data []rune) bool {
+ return chunkList.Push(data)
}, eventBox, opts.ReadZero}
go reader.ReadSource()
}
@@ -151,10 +151,10 @@ func Run(opts *Options) {
if streamingFilter {
reader := Reader{
- func(str string) bool {
- item := chunkList.trans(&str, 0)
+ func(runes []rune) bool {
+ item := chunkList.trans(runes, 0)
if item != nil && pattern.MatchItem(item) {
- fmt.Println(*item.text)
+ fmt.Println(string(item.text))
}
return false
}, eventBox, opts.ReadZero}