diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 15:16:55 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 15:16:55 +0200 |
| commit | 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe (patch) | |
| tree | 358e331945b8206ed4a72703e3aedfe8ea7cdcdb /internal/cond/eval.go | |
| parent | 1d3f2d1e4c59867024470d3444e12698b7ebb22e (diff) | |
| download | krino-0.0.5.tar.gz krino-0.0.5.zip | |
krino: 0.0.5 — keyword cache, t and d in reviewv0.0.5
Diffstat (limited to 'internal/cond/eval.go')
| -rw-r--r-- | internal/cond/eval.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/internal/cond/eval.go b/internal/cond/eval.go index e3093af..3cec110 100644 --- a/internal/cond/eval.go +++ b/internal/cond/eval.go @@ -19,7 +19,10 @@ type Facts interface { Size() int64 ModTime() time.Time Now() time.Time - Content(ignoreCase, fold bool) (string, error) // normalised with norm.Text + // ContentContains reports the index of the first of keywords, each + // normalised under opt with norm.Text, that the file's text contains, or + // -1 when it contains none. + ContentContains(opt Options, keywords []string) (int, error) Duplicate(dirs []string) (original string, ok bool, err error) Matched() bool // an earlier rule matched this file } @@ -167,14 +170,16 @@ func (c *Cond) evalLeaf(n *node, f Facts) (ok bool, reason, warn string, caps [] return false, "", "", nil case kContent: - text, err := f.Content(c.opt.IgnoreCase, c.opt.Fold) + norms := make([]string, len(n.keywords)) + for i, kw := range n.keywords { + norms[i] = kw.norm + } + i, err := f.ContentContains(c.opt, norms) if err != nil { return false, "", "content unreadable: " + err.Error(), nil } - for _, kw := range n.keywords { - if strings.Contains(text, kw.norm) { - return true, `content "` + kw.src + `"`, "", nil - } + if i >= 0 { + return true, `content "` + n.keywords[i].src + `"`, "", nil } return false, "", "", nil |
