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
This commit is contained in:
Junegunn Choi
2015-08-02 14:00:18 +09:00
parent 634670e3ea
commit 0ea66329b8
18 changed files with 163 additions and 154 deletions

View File

@@ -78,13 +78,13 @@ func IsTty() bool {
return int(C.isatty(C.int(os.Stdin.Fd()))) != 0
}
func TrimRight(runes *[]rune) []rune {
func TrimRight(runes []rune) []rune {
var i int
for i = len(*runes) - 1; i >= 0; i-- {
char := (*runes)[i]
for i = len(runes) - 1; i >= 0; i-- {
char := runes[i]
if char != ' ' && char != '\t' {
break
}
}
return (*runes)[0 : i+1]
return runes[0 : i+1]
}