tick: dedupe rule-by-name map building (V-581)

stopFinishedAlarms and repeatableRules each built their own
map[string]rule (one keyed to loop.Rule, one to bool) from t.rules on
every call. Factored into rulesByName(), one map[string]loop.Rule both
callers read.
This commit is contained in:
2026-08-06 02:08:05 +04:00
parent 0feb8d3dbd
commit b6680398c3
+14 -9
View File
@@ -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