From 1d4057c20907b7d263d6f2b8cb4350a024859dfe Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 14 Aug 2016 00:39:44 +0900 Subject: [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. --- src/options_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/options_test.go') 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)) } } -- cgit v1.2.3