From 16e413799363871c1efd73527fba299dfdfadfd3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 May 2026 19:42:30 +0300 Subject: refactor: extract outputFormatter collaborator from eventLoop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The printCb and warningCb function fields on eventLoop bundled two distinct concerns (pair emission and warning delivery) directly on the event-processing struct. This commit extracts them into a dedicated outputFormatter type that owns these callbacks plus emit() and notifyWarning() helper methods. outputFormatter is embedded (not pointed-to) in eventLoop so that existing call sites — including tests that write el.printCb = ... and el.warningCb = ... directly — require no changes beyond the three struct-literal sites in eventloop_filter_test.go that used field initialiser syntax. fdTracker and commResolver were already proper collaborator types; only the output concern needed extraction. Co-Authored-By: Claude Sonnet 4.6 --- internal/eventloop_runtime.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'internal/eventloop_runtime.go') diff --git a/internal/eventloop_runtime.go b/internal/eventloop_runtime.go index 01bc798..5addd46 100644 --- a/internal/eventloop_runtime.go +++ b/internal/eventloop_runtime.go @@ -23,6 +23,8 @@ func (e *eventLoop) run(ctx context.Context, rawCh <-chan []byte) { } e.startTime = time.Now() + // emit() already handles a nil printCb safely, but guard here so that + // hot-path event emission never pays for a nil check inside the loop. if e.printCb == nil { e.printCb = func(ep *event.Pair) { ep.Recycle() } } @@ -32,7 +34,7 @@ func (e *eventLoop) run(ctx context.Context, rawCh <-chan []byte) { return } for ep := range e.events(ctx, rawCh) { - e.printCb(ep) + e.emit(ep) e.numSyscallsAfterFilter++ } } @@ -58,12 +60,13 @@ func (e *eventLoop) runSynchronously(ctx context.Context, rawCh <-chan []byte) { } } -// drainPairs consumes all immediately available pairs from the buffered channel. +// drainPairs consumes all immediately available pairs from the buffered channel, +// routing each completed pair through the outputFormatter. func (e *eventLoop) drainPairs(pairs <-chan *event.Pair) { for { select { case ep := <-pairs: - e.printCb(ep) + e.emit(ep) e.numSyscallsAfterFilter++ default: return -- cgit v1.2.3