@@ -151,15 +151,15 @@ func (m *Matcher) DisableRebuild() {
151151//
152152// Currently an AddPattern, DeletePattern, or MatchesForFields can
153153// trigger a rebuild. When a rebuild is triggered, it's executed
154- // synchronous, the the Add/Delete method doesn't return until the
155- // rebuild is complete.
154+ // synchronously: the the Add/Delete/Match method doesn't return until
155+ // the rebuild is complete.
156156type rebuildTrigger interface {
157157 // Rebuild should return true to trigger a rebuild.
158158 //
159- // This method is called by AddPattern and DeletePattern.
160- // added is true when called by AddPattern; false
161- // otherwise. These methods do not return until the rebuild is
162- // complete, so beware.
159+ // This method is called by AddPatter,DeletePattern, and
160+ // MatchesForFields. added is true when called by AddPattern;
161+ // false otherwise. These methods currently do not return
162+ // until the rebuild is complete, so beware.
163163 Rebuild (added bool , s * Stats ) bool
164164}
165165
@@ -178,9 +178,9 @@ func NewMatcher(s LivePatternsState) *Matcher {
178178 }
179179}
180180
181- // maybeRebuild calls rebuildTrigger (if not) and then calls rebuild()
182- // if that trigger said to do that. If rebuildTrigger is nil, no
183- // rebuild is executed.
181+ // maybeRebuild calls rebuildTrigger and calls rebuild() if that
182+ // trigger said to do that. If rebuildTrigger is nil, no rebuild is
183+ // executed.
184184//
185185// This method assumes the caller has a write lock.
186186func (m * Matcher ) maybeRebuild (added bool ) error {
@@ -194,8 +194,9 @@ func (m *Matcher) maybeRebuild(added bool) error {
194194 return nil
195195}
196196
197- // AddPattern calls the underlying AddPattern method and then maybe
198- // rebuilds the index (if the AddPattern succeeded).
197+ // AddPattern calls the underlying quamina.CoreMatcher.AddPattern
198+ // method and then maybe rebuilds the index (if the AddPattern
199+ // succeeded).
199200func (m * Matcher ) AddPattern (x quamina.X , pat string ) error {
200201 var err error
201202
@@ -216,17 +217,20 @@ func (m *Matcher) AddPattern(x quamina.X, pat string) error {
216217}
217218
218219// NewFJ just calls quamina.FJ.
220+ //
221+ // Here for convenience only.
219222func NewFJ (m * Matcher ) quamina.Flattener {
220223 return quamina .NewFJ (m .Matcher )
221224}
222225
223226// NewFJ calls quamina.NewFJ with this Matcher's core quamina.Matcher
227+ //
228+ // Here for convenience only.
224229func (m * Matcher ) NewFJ () quamina.Flattener {
225230 return quamina .NewFJ (m .Matcher )
226231}
227232
228- // MatchesForJSONEvent calls the underlying MatchesForJSONEvent method
229- // and then maybe rebuilds the index.
233+ // MatchesForJSONEvent calls MatchesForFields with a new Flattener.
230234func (m * Matcher ) MatchesForJSONEvent (event []byte ) ([]quamina.X , error ) {
231235 fs , err := m .NewFJ ().Flatten (event )
232236 if err != nil {
@@ -235,6 +239,9 @@ func (m *Matcher) MatchesForJSONEvent(event []byte) ([]quamina.X, error) {
235239 return m .MatchesForFields (fs )
236240}
237241
242+ // MatchesForFields calls the underlying
243+ // quamina.CoreMatcher.MatchesForFields and then maybe rebuilds the
244+ // index.
238245func (m * Matcher ) MatchesForFields (fields []quamina.Field ) ([]quamina.X , error ) {
239246
240247 xs , err := m .Matcher .MatchesForFields (fields )
@@ -246,9 +253,6 @@ func (m *Matcher) MatchesForFields(fields []quamina.Field) ([]quamina.X, error)
246253
247254 acc := make ([]quamina.X , 0 , len (xs ))
248255
249- // We're updating stats.Filtered, so we need a write lock. If
250- // we forget about stats.Filtered, we can live with only a
251- // read lock here.
252256 var emitted , filtered int64
253257 for _ , x := range xs {
254258 have , err := m .live .Contains (x )
@@ -272,16 +276,9 @@ func (m *Matcher) MatchesForFields(fields []quamina.Field) ([]quamina.X, error)
272276 return acc , nil
273277}
274278
275- // DeletePattern "removes" the pattern from the index and maybe
276- // rebuilds the index.
277- //
278- // The return boolean when true indicates that at least one pattern
279- // for x was removed.
279+ // DeletePattern removes the pattern from the index and maybe rebuilds
280+ // the index.
280281func (m * Matcher ) DeletePattern (x quamina.X ) error {
281- // Maybe better to return (int,error) as in
282- // LivePatternStats.Delete(), or maybe just return an error
283- // and nothing else.
284-
285282 n , err := m .live .Delete (x )
286283 if err == nil {
287284 if 0 < n {
0 commit comments