From 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 15:16:55 +0200 Subject: krino: 0.0.5 — keyword cache, t and d in review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/cond/eval.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'internal/cond/eval.go') 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 -- cgit v1.3