diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 00:39:44 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 00:41:30 +0900 |
| commit | 1d4057c20907b7d263d6f2b8cb4350a024859dfe (patch) | |
| tree | adb1edd9c4f1806cd65f8c5117645c22618c7301 /src/util/util.go | |
| parent | 822b86942c4ffb0dbf7fd096584d2970675f3ebc (diff) | |
| download | fzf-1d4057c20907b7d263d6f2b8cb4350a024859dfe.tar.gz | |
[perf] Avoid allocating rune array for ascii string
In the best case (all ascii), this reduces the memory footprint by 60%
and the response time by 15% to 20%. In the worst case (every line has
non-ascii characters), 3 to 4% overhead is observed.
Diffstat (limited to 'src/util/util.go')
| -rw-r--r-- | src/util/util.go | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/src/util/util.go b/src/util/util.go index 4f3d409d..90cc28b4 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -7,7 +7,6 @@ import ( "os" "os/exec" "time" - "unicode/utf8" ) // Max returns the largest integer @@ -84,34 +83,6 @@ func IsTty() bool { return int(C.isatty(C.int(os.Stdin.Fd()))) != 0 } -// TrimRight returns rune array with trailing white spaces cut off -func TrimRight(runes []rune) []rune { - var i int - for i = len(runes) - 1; i >= 0; i-- { - char := runes[i] - if char != ' ' && char != '\t' { - break - } - } - return runes[0 : i+1] -} - -// BytesToRunes converts byte array into rune array -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 -} - // TrimLen returns the length of trimmed rune array func TrimLen(runes []rune) int { var i int |
