aboutsummaryrefslogtreecommitdiff
path: root/internal/cond
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cond')
-rw-r--r--internal/cond/eval.go8
-rw-r--r--internal/cond/eval_test.go3
2 files changed, 10 insertions, 1 deletions
diff --git a/internal/cond/eval.go b/internal/cond/eval.go
index 2ae31fb..7d8e00d 100644
--- a/internal/cond/eval.go
+++ b/internal/cond/eval.go
@@ -28,6 +28,12 @@ type Facts interface {
// an earlier rule could not be decided (its condition was unknown): with
// no match and an undecided rule, (matched) is unknown.
Matched() (matched, undecided bool)
+ // Folded is norm.FoldMapped(subj), memoised per file. Folding is the
+ // expensive half of a name test on a name with diacritics, and the
+ // same name is folded again by every name test of every rule; the
+ // implementation holds one file at a time, so a small memo there
+ // removes the repetition entirely.
+ Folded(subj string) norm.Folded
}
// Result is the outcome of evaluating a Cond against one file's Facts.
@@ -243,7 +249,7 @@ func (c *Cond) evalLeaf(n *node, f Facts) (ok bool, reason, warn string, caps []
// back from the original, so {1} keeps the name's diacritics.
folded := norm.Folded{Text: subj}
if c.opt.Fold {
- folded = norm.FoldMapped(subj)
+ folded = f.Folded(subj)
}
for _, p := range n.patterns {
loc := p.re.FindStringSubmatchIndex(folded.Text)
diff --git a/internal/cond/eval_test.go b/internal/cond/eval_test.go
index 5074557..7f06afd 100644
--- a/internal/cond/eval_test.go
+++ b/internal/cond/eval_test.go
@@ -39,6 +39,9 @@ func (f *fake) Size() int64 { return f.size }
func (f *fake) ModTime() time.Time { return now.Add(-f.age) }
func (f *fake) Now() time.Time { return now }
func (f *fake) Matched() (bool, bool) { return f.matched, f.matchedUnknown }
+
+// Folded has no memo here: a fake stands in for one file in one test.
+func (f *fake) Folded(subj string) norm.Folded { return norm.FoldMapped(subj) }
func (f *fake) ContentContains(opt Options, keywords []string) (int, error) {
f.contentCalls++
if f.rawErr != nil {