diff --git a/cmd/mavend/tick.go b/cmd/mavend/tick.go index 9de2b74..76b0911 100644 --- a/cmd/mavend/tick.go +++ b/cmd/mavend/tick.go @@ -319,10 +319,7 @@ func (t *tickLoop) stopFinishedAlarms(ctx context.Context, keys []string, state if len(keys) == 0 { return nil } - byName := make(map[string]loop.Rule, len(t.rules)) - for _, r := range t.rules { - byName[r.Name] = r - } + byName := t.rulesByName() live := keys[:0:0] for _, key := range keys { outcome := "" @@ -381,19 +378,27 @@ func (t *tickLoop) repeatableRules(keys []string) []string { if len(keys) == 0 { return nil } - wired := make(map[string]bool, len(t.rules)) - for _, r := range t.rules { - wired[r.Name] = true - } + wired := t.rulesByName() out := keys[:0:0] for _, k := range keys { - if wired[k] { + if _, ok := wired[k]; ok { out = append(out, k) } } return out } +// rulesByName indexes the wired rule set by name, for the two lookups above +// that only care whether a key is still wired (repeatableRules) or need the +// rule itself (stopFinishedAlarms). +func (t *tickLoop) rulesByName() map[string]loop.Rule { + byName := make(map[string]loop.Rule, len(t.rules)) + for _, r := range t.rules { + byName[r.Name] = r + } + return byName +} + // cachePhrase keeps the latest phrased nudge per rule for the sev4-repeat // path. writing under a mutex; the repeat path reads under the same. the // cache is bounded by the rule count (≤ ~30 per spec) so eviction is not a