From 8349e7504a4ff8cc33170786622d3d09dc110284 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 30 Mar 2026 18:53:16 +0700 Subject: [PATCH] [ai] Add a review guideline about make_state. --- REVIEW.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/REVIEW.md b/REVIEW.md index 1c906e13e3..0623131f0f 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -453,6 +453,23 @@ if (!child->isHidden()) { The same applies to any logic that depends on a previous `show()`/`hide()` call: skip blocks, layout branches, opacity decisions, etc. +## Consolidate make_state calls into a single State struct + +Every `make_state` is a separate heap allocation. When a function needs multiple pieces of lambda-captured mutable state, define a local `struct State` with all fields and call `make_state()` once, then capture the resulting pointer everywhere. + +```cpp +// BAD - two allocations: +const auto shown = lifetime.make_state(false); +const auto count = lifetime.make_state(0); + +// GOOD - one allocation: +struct State { + bool shown = false; + int count = 0; +}; +const auto state = lifetime.make_state(); +``` + ## Static member functions use PascalCase Non-static member functions use camelCase (`startBatch`, `finalize`). Static member functions use PascalCase (`ShouldTrack`, `Parse`, `Create`), matching the convention for free functions.