From 8a9dfefb3a45c6ead7d8caaad0c135ddb56c992e Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Fri, 20 Feb 2026 14:05:22 +0900 Subject: [PATCH] change applyFn to interface --- filter/base.go | 14 ++++++++++---- filter/fuzzy.go | 2 +- filter/regexp.go | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/filter/base.go b/filter/base.go index fafb444..1122c44 100644 --- a/filter/base.go +++ b/filter/base.go @@ -41,11 +41,17 @@ func (c *LineCollector) Lines() []line.Line { return c.lines } +// lineApplier is implemented by filter types that embed baseFilter to provide +// their type-specific matching logic. +type lineApplier interface { + applyInternal(ctx context.Context, lines []line.Line, em LineEmitter) error +} + // baseFilter provides shared implementations of Apply, ApplyCollect, // NewContext, and BufSize for filters that follow the applyInternal pattern. -// Filters embed this type and set applyFn to their type-specific matching logic. +// Filters embed this type and set impl to their concrete filter value. type baseFilter struct { - applyFn func(ctx context.Context, lines []line.Line, em LineEmitter) error + impl lineApplier } // NewContext returns a context initialized with the given query for pipeline use. @@ -59,13 +65,13 @@ func (b *baseFilter) BufSize() int { // Apply runs the filter's matching logic on lines, sending matches to out. func (b *baseFilter) Apply(ctx context.Context, lines []line.Line, out pipeline.ChanOutput) error { - return b.applyFn(ctx, lines, &chanEmitter{out: out}) + return b.impl.applyInternal(ctx, lines, &chanEmitter{out: out}) } // ApplyCollect runs the filter and returns matched lines directly as a slice, // bypassing channel-based output for better performance in parallel paths. func (b *baseFilter) ApplyCollect(ctx context.Context, lines []line.Line) ([]line.Line, error) { c := NewLineCollector(len(lines) / 2) - err := b.applyFn(ctx, lines, c) + err := b.impl.applyInternal(ctx, lines, c) return c.Lines(), err } diff --git a/filter/fuzzy.go b/filter/fuzzy.go index 6d79f83..dea611e 100644 --- a/filter/fuzzy.go +++ b/filter/fuzzy.go @@ -34,7 +34,7 @@ func NewFuzzy(sortLongest bool) *Fuzzy { ff := &Fuzzy{ sortLongest: sortLongest, } - ff.applyFn = ff.applyInternal + ff.impl = ff return ff } diff --git a/filter/regexp.go b/filter/regexp.go index 00326a1..0defb08 100644 --- a/filter/regexp.go +++ b/filter/regexp.go @@ -127,7 +127,7 @@ func newRegexpFilter(name string, flags regexpFlags, quotemeta bool) *Regexp { quotemeta: quotemeta, name: name, } - rf.applyFn = rf.applyInternal + rf.impl = rf return rf }