From f8fdf9618adf831b614a9b69e90eca53b9e37a28 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 20 Aug 2016 02:06:57 +0900 Subject: [PATCH] No need to cache the result in filtering mode (--filter) --- src/core.go | 2 +- src/pattern.go | 6 +++--- src/pattern_test.go | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core.go b/src/core.go index 78dddc0..70f2da5 100644 --- a/src/core.go +++ b/src/core.go @@ -143,7 +143,7 @@ func Run(opts *Options) { } patternBuilder := func(runes []rune) *Pattern { return BuildPattern( - opts.Fuzzy, opts.Extended, opts.Case, forward, + opts.Fuzzy, opts.Extended, opts.Case, forward, opts.Filter == nil, opts.Nth, opts.Delimiter, runes) } matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox) diff --git a/src/pattern.go b/src/pattern.go index ef14826..faafa0b 100644 --- a/src/pattern.go +++ b/src/pattern.go @@ -75,7 +75,7 @@ func clearChunkCache() { // BuildPattern builds Pattern object from the given arguments func BuildPattern(fuzzy bool, extended bool, caseMode Case, forward bool, - nth []Range, delimiter Delimiter, runes []rune) *Pattern { + cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern { var asString string if extended { @@ -89,7 +89,7 @@ func BuildPattern(fuzzy bool, extended bool, caseMode Case, forward bool, return cached } - caseSensitive, cacheable := true, true + caseSensitive := true termSets := []termSet{} if extended { @@ -99,7 +99,7 @@ func BuildPattern(fuzzy bool, extended bool, caseMode Case, forward bool, for idx, term := range termSet { // If the query contains inverse search terms or OR operators, // we cannot cache the search scope - if idx > 0 || term.inv { + if !cacheable || idx > 0 || term.inv { cacheable = false break Loop } diff --git a/src/pattern_test.go b/src/pattern_test.go index 2a391f4..43bc5e0 100644 --- a/src/pattern_test.go +++ b/src/pattern_test.go @@ -69,7 +69,7 @@ func TestParseTermsEmpty(t *testing.T) { func TestExact(t *testing.T) { defer clearPatternCache() clearPatternCache() - pattern := BuildPattern(true, true, CaseSmart, true, + pattern := BuildPattern(true, true, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("'abc")) res := algo.ExactMatchNaive( pattern.caseSensitive, pattern.forward, util.RunesToChars([]rune("aabbcc abc")), pattern.termSets[0][0].text) @@ -81,7 +81,7 @@ func TestExact(t *testing.T) { func TestEqual(t *testing.T) { defer clearPatternCache() clearPatternCache() - pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$")) + pattern := BuildPattern(true, true, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("^AbC$")) match := func(str string, sidxExpected int, eidxExpected int) { res := algo.EqualMatch( @@ -97,17 +97,17 @@ func TestEqual(t *testing.T) { func TestCaseSensitivity(t *testing.T) { defer clearPatternCache() clearPatternCache() - pat1 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("abc")) + pat1 := BuildPattern(true, false, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("abc")) clearPatternCache() - pat2 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("Abc")) + pat2 := BuildPattern(true, false, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("Abc")) clearPatternCache() - pat3 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("abc")) + pat3 := BuildPattern(true, false, CaseIgnore, true, true, []Range{}, Delimiter{}, []rune("abc")) clearPatternCache() - pat4 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("Abc")) + pat4 := BuildPattern(true, false, CaseIgnore, true, true, []Range{}, Delimiter{}, []rune("Abc")) clearPatternCache() - pat5 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("abc")) + pat5 := BuildPattern(true, false, CaseRespect, true, true, []Range{}, Delimiter{}, []rune("abc")) clearPatternCache() - pat6 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("Abc")) + pat6 := BuildPattern(true, false, CaseRespect, true, true, []Range{}, Delimiter{}, []rune("Abc")) if string(pat1.text) != "abc" || pat1.caseSensitive != false || string(pat2.text) != "Abc" || pat2.caseSensitive != true || @@ -120,7 +120,7 @@ func TestCaseSensitivity(t *testing.T) { } func TestOrigTextAndTransformed(t *testing.T) { - pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("jg")) + pattern := BuildPattern(true, true, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("jg")) tokens := Tokenize(util.RunesToChars([]rune("junegunn")), Delimiter{}) trans := Transform(tokens, []Range{Range{1, 1}}) @@ -150,7 +150,7 @@ func TestOrigTextAndTransformed(t *testing.T) { func TestCacheKey(t *testing.T) { test := func(extended bool, patStr string, expected string, cacheable bool) { - pat := BuildPattern(true, extended, CaseSmart, true, []Range{}, Delimiter{}, []rune(patStr)) + pat := BuildPattern(true, extended, CaseSmart, true, true, []Range{}, Delimiter{}, []rune(patStr)) if pat.CacheKey() != expected { t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey()) }