summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-08-02 14:25:57 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-08-02 14:25:57 +0900
commite13bafc1abaea9a9f3142eb58be1e977ca97e114 (patch)
tree98c07483e3fb5057feb8c8854d51034c0856b08c /src/util
parent0ea66329b84cc6e4f8ff61ee99c00bb238070247 (diff)
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
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/util.go b/src/util/util.go
index a0e12696..eeeb75f4 100644
--- a/src/util/util.go
+++ b/src/util/util.go
@@ -6,6 +6,7 @@ import "C"
import (
"os"
"time"
+ "unicode/utf8"
)
// Max returns the largest integer
@@ -88,3 +89,18 @@ func TrimRight(runes []rune) []rune {
}
return runes[0 : i+1]
}
+
+func BytesToRunes(bytea []byte) []rune {
+ 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)
+ }
+ }
+ return runes
+}