Performance fix - unnecessary rune convertion on --ansi

> time cat /tmp/list | fzf-0.10.1-darwin_amd64 --ansi -fqwerty > /dev/null

    real    0m4.364s
    user    0m8.231s
    sys     0m0.820s

    > time cat /tmp/list | fzf --ansi -fqwerty > /dev/null

    real    0m4.624s
    user    0m5.755s
    sys     0m0.732s
This commit is contained in:
Junegunn Choi
2015-08-02 14:25:57 +09:00
parent 0ea66329b8
commit e13bafc1ab
6 changed files with 52 additions and 42 deletions

View File

@@ -5,14 +5,13 @@ import (
"io"
"os"
"os/exec"
"unicode/utf8"
"github.com/junegunn/fzf/src/util"
)
// Reader reads from command or standard input
type Reader struct {
pusher func([]rune) bool
pusher func([]byte) bool
eventBox *util.EventBox
delimNil bool
}
@@ -42,21 +41,10 @@ func (r *Reader) feed(src io.Reader) {
// end in delim.
bytea, err := reader.ReadBytes(delim)
if len(bytea) > 0 {
runes := make([]rune, 0, len(bytea))
for i := 0; i < len(bytea); {
if bytea[i] < utf8.RuneSelf {
runes = append(runes, rune(bytea[i]))
i++
} else {
r, sz := utf8.DecodeRune(bytea[i:])
i += sz
runes = append(runes, r)
}
}
if err == nil {
runes = runes[:len(runes)-1]
bytea = bytea[:len(bytea)-1]
}
if r.pusher(runes) {
if r.pusher(bytea) {
r.eventBox.Set(EvtReadNew, nil)
}
}