diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-04-17 22:23:52 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-04-17 22:23:52 +0900 |
commit | 2fe1e28220c543ddbf4e12ee7396e44ee85ad8e0 (patch) | |
tree | 82c77b5e639cd66b941356788bcb8e0e053949be /src/util/util.go | |
parent | 288131ac5a895ba335681339d85ee039557490da (diff) |
Improvements in performance and memory usage
I profiled fzf and it turned out that it was spending significant amount
of time repeatedly converting character arrays into Unicode codepoints.
This commit greatly improves search performance after the initial scan
by memoizing the converted results.
This commit also addresses the problem of unbounded memory usage of fzf.
fzf is a short-lived process that usually processes small input, so it
was implemented to cache the intermediate results very aggressively with
no notion of cache expiration/eviction. I still think a proper
implementation of caching scheme is definitely an overkill. Instead this
commit introduces limits to the maximum size (or minimum selectivity) of
the intermediate results that can be cached.
Diffstat (limited to 'src/util/util.go')
-rw-r--r-- | src/util/util.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/util.go b/src/util/util.go index 931b14a8..511de1e5 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -77,3 +77,14 @@ func Between(val int, min int, max int) bool { func IsTty() bool { return int(C.isatty(C.int(os.Stdin.Fd()))) != 0 } + +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] +} |