No need to cache the result in filtering mode (--filter)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 827a83e · Browse files · 3 files·+14 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+14 added−14 removed
- other:+14 added−14 removed
Provenance
- Commit
f8fdf96- Tree
c08b729- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
827a83e
3 files changed+14 added−14 removed
modified:src/core.go+1 added-1 removed
141 unmodified lines142 }143 }144 patternBuilder := func(runes []rune) *Pattern {145 return BuildPattern(146- opts.Fuzzy, opts.Extended, opts.Case, forward,146+ opts.Fuzzy, opts.Extended, opts.Case, forward, opts.Filter == nil,147 opts.Nth, opts.Delimiter, runes)148 }149 matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)150 135 unmodified linesmodified:src/pattern_test.go+10 added-10 removed
67 unmodified lines68 69 func TestExact(t *testing.T) {70 defer clearPatternCache()71 clearPatternCache()72- pattern := BuildPattern(true, true, CaseSmart, true,72+ pattern := BuildPattern(true, true, CaseSmart, true, true,73 []Range{}, Delimiter{}, []rune("'abc"))74 res := algo.ExactMatchNaive(75 pattern.caseSensitive, pattern.forward, util.RunesToChars([]rune("aabbcc abc")), pattern.termSets[0][0].text)76 if res.Start != 7 || res.End != 10 {3 unmodified lines80 81 func TestEqual(t *testing.T) {82 defer clearPatternCache()83 clearPatternCache()84- pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$"))84+ pattern := BuildPattern(true, true, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("^AbC$"))85 86 match := func(str string, sidxExpected int, eidxExpected int) {87 res := algo.EqualMatch(88 pattern.caseSensitive, pattern.forward, util.RunesToChars([]rune(str)), pattern.termSets[0][0].text)7 unmodified lines96 97 func TestCaseSensitivity(t *testing.T) {98 defer clearPatternCache()99 clearPatternCache()100- pat1 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("abc"))100+ pat1 := BuildPattern(true, false, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("abc"))101 clearPatternCache()102- pat2 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("Abc"))102+ pat2 := BuildPattern(true, false, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("Abc"))103 clearPatternCache()104- pat3 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("abc"))104+ pat3 := BuildPattern(true, false, CaseIgnore, true, true, []Range{}, Delimiter{}, []rune("abc"))105 clearPatternCache()106- pat4 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("Abc"))106+ pat4 := BuildPattern(true, false, CaseIgnore, true, true, []Range{}, Delimiter{}, []rune("Abc"))107 clearPatternCache()108- pat5 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("abc"))108+ pat5 := BuildPattern(true, false, CaseRespect, true, true, []Range{}, Delimiter{}, []rune("abc"))109 clearPatternCache()110- pat6 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("Abc"))110+ pat6 := BuildPattern(true, false, CaseRespect, true, true, []Range{}, Delimiter{}, []rune("Abc"))111 112 if string(pat1.text) != "abc" || pat1.caseSensitive != false ||113 string(pat2.text) != "Abc" || pat2.caseSensitive != true ||114 string(pat3.text) != "abc" || pat3.caseSensitive != false ||4 unmodified lines119 }120 }121 122 func TestOrigTextAndTransformed(t *testing.T) {123- pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("jg"))123+ pattern := BuildPattern(true, true, CaseSmart, true, true, []Range{}, Delimiter{}, []rune("jg"))124 tokens := Tokenize(util.RunesToChars([]rune("junegunn")), Delimiter{})125 trans := Transform(tokens, []Range{Range{1, 1}})126 127 origBytes := []byte("junegunn.choi")21 unmodified lines149 }150 151 func TestCacheKey(t *testing.T) {152 test := func(extended bool, patStr string, expected string, cacheable bool) {153- pat := BuildPattern(true, extended, CaseSmart, true, []Range{}, Delimiter{}, []rune(patStr))153+ pat := BuildPattern(true, extended, CaseSmart, true, true, []Range{}, Delimiter{}, []rune(patStr))154 if pat.CacheKey() != expected {155 t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())156 }157 if pat.cacheable != cacheable {14 unmodified linesmodified:src/pattern.go+3 added-3 removed
73 unmodified lines74 }75 76 // BuildPattern builds Pattern object from the given arguments77 func BuildPattern(fuzzy bool, extended bool, caseMode Case, forward bool,78- nth []Range, delimiter Delimiter, runes []rune) *Pattern {78+ cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {79 80 var asString string81 if extended {82 asString = strings.Trim(string(runes), " ")5 unmodified lines88 if found {89 return cached90 }91 92- caseSensitive, cacheable := true, true92+ caseSensitive := true93 termSets := []termSet{}94 95 if extended {96 termSets = parseTerms(fuzzy, caseMode, asString)1 unmodified line98 for _, termSet := range termSets {99 for idx, term := range termSet {100 // If the query contains inverse search terms or OR operators,101 // we cannot cache the search scope102- if idx > 0 || term.inv {102+ if !cacheable || idx > 0 || term.inv {103 cacheable = false104 break Loop105 }106 }269 unmodified lines