summaryrefslogtreecommitdiff
path: root/src/pattern.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2025-01-13 17:37:50 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2025-01-13 17:37:50 +0900
commit56fef7c8df2713261fbdbd396aa81ed23d9a945a (patch)
treeb8f8c52f84f7c4a37cca062dcc871e91fc63f160 /src/pattern.go
parentba0935c71f5507958056201ddad2fc48674a586d (diff)
downloadfzf-56fef7c8df2713261fbdbd396aa81ed23d9a945a.tar.gz
Simplify nth comparison when reusing transformed tokens
Diffstat (limited to 'src/pattern.go')
-rw-r--r--src/pattern.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/pattern.go b/src/pattern.go
index 9a386280..dd9c5292 100644
--- a/src/pattern.go
+++ b/src/pattern.go
@@ -60,6 +60,7 @@ type Pattern struct {
cacheKey string
delimiter Delimiter
nth []Range
+ revision int
procFun map[termType]algo.Algo
cache *ChunkCache
}
@@ -72,7 +73,7 @@ func init() {
// BuildPattern builds Pattern object from the given arguments
func BuildPattern(cache *ChunkCache, patternCache map[string]*Pattern, fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
- withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
+ withPos bool, cacheable bool, nth []Range, delimiter Delimiter, revision int, runes []rune) *Pattern {
var asString string
if extended {
@@ -140,6 +141,7 @@ func BuildPattern(cache *ChunkCache, patternCache map[string]*Pattern, fuzzy boo
sortable: sortable,
cacheable: cacheable,
nth: nth,
+ revision: revision,
delimiter: delimiter,
cache: cache,
procFun: make(map[termType]algo.Algo)}
@@ -394,23 +396,14 @@ func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Of
func (p *Pattern) transformInput(item *Item) []Token {
if item.transformed != nil {
transformed := *item.transformed
- if len(transformed.nth) == len(p.nth) {
- same := true
- for idx, rangeItem := range transformed.nth {
- if rangeItem != p.nth[idx] {
- same = false
- break
- }
- }
- if same {
- return transformed.tokens
- }
+ if transformed.revision == p.revision {
+ return transformed.tokens
}
}
tokens := Tokenize(item.text.ToString(), p.delimiter)
ret := Transform(tokens, p.nth)
- item.transformed = &transformed{p.nth, ret}
+ item.transformed = &transformed{p.revision, ret}
return ret
}