summaryrefslogtreecommitdiff
path: root/src/options_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-08-14 00:39:44 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-08-14 00:41:30 +0900
commit1d4057c20907b7d263d6f2b8cb4350a024859dfe (patch)
treeadb1edd9c4f1806cd65f8c5117645c22618c7301 /src/options_test.go
parent822b86942c4ffb0dbf7fd096584d2970675f3ebc (diff)
downloadfzf-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/options_test.go')
-rw-r--r--src/options_test.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/options_test.go b/src/options_test.go
index eb1dfa9c..c1bc9147 100644
--- a/src/options_test.go
+++ b/src/options_test.go
@@ -5,6 +5,7 @@ import (
"testing"
"github.com/junegunn/fzf/src/curses"
+ "github.com/junegunn/fzf/src/util"
)
func TestDelimiterRegex(t *testing.T) {
@@ -42,24 +43,24 @@ func TestDelimiterRegex(t *testing.T) {
func TestDelimiterRegexString(t *testing.T) {
delim := delimiterRegexp("*")
- tokens := Tokenize([]rune("-*--*---**---"), delim)
+ tokens := Tokenize(util.RunesToChars([]rune("-*--*---**---")), delim)
if delim.regex != nil ||
- string(tokens[0].text) != "-*" ||
- string(tokens[1].text) != "--*" ||
- string(tokens[2].text) != "---*" ||
- string(tokens[3].text) != "*" ||
- string(tokens[4].text) != "---" {
+ tokens[0].text.ToString() != "-*" ||
+ tokens[1].text.ToString() != "--*" ||
+ tokens[2].text.ToString() != "---*" ||
+ tokens[3].text.ToString() != "*" ||
+ tokens[4].text.ToString() != "---" {
t.Errorf("%s %s %d", delim, tokens, len(tokens))
}
}
func TestDelimiterRegexRegex(t *testing.T) {
delim := delimiterRegexp("--\\*")
- tokens := Tokenize([]rune("-*--*---**---"), delim)
+ tokens := Tokenize(util.RunesToChars([]rune("-*--*---**---")), delim)
if delim.str != nil ||
- string(tokens[0].text) != "-*--*" ||
- string(tokens[1].text) != "---*" ||
- string(tokens[2].text) != "*---" {
+ tokens[0].text.ToString() != "-*--*" ||
+ tokens[1].text.ToString() != "---*" ||
+ tokens[2].text.ToString() != "*---" {
t.Errorf("%s %d", tokens, len(tokens))
}
}