Repository navigation
refactor: Replace hand-written erase loops with std::erase and std::erase_if - #3685
CryoTheRenegade wants to merge 4 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. WalkthroughThe pull request adds an erase compatibility adapter and replaces manual container-removal loops with ChangesContainer erase adoption
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Suggested labels: Suggested reviewers: Merge Risk:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge.
|
…ace of hand-written erase loops Utility/erase_adapter.h provides C++20 std::erase and std::erase_if. VC6 gets function templates that use the erase-iterator loop the code already used. Common/STLTypedefs.h includes it, so all GameEngine code gets it. The converted loops only removed elements that match a predicate without side effects. The predicates are file-scope functors because VC6 has no lambdas. Eva::reset erased every element and now calls clear(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a085f97 to
0b9f43c
Compare
…IONS is never defined Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… above translateGameMessage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unctions in Squad.cpp Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This follows #3532 and #3652, which added C++20 functions to the VC6 adapters so the code can call the standard versions. The code base has many hand-written loops that erase the elements of a container that match a value or a condition. C++20 has
std::eraseandstd::erase_iffor this, so this PR adds them for VC6 and uses them where a loop does nothing but remove the matching elements.The adapter is named after the functions, like
interlocked_adapter.h, because C++20 has no single header for them. The VC6 versions do not work onstd::maporstd::set, because STLport'serase(iterator)returnsvoidfor those. The header comment lists this and the other differences from the standard functions.Converted loops (both games unless marked Core). VC6 has no lambdas, so each condition is a small functor struct with its own name, like
GameSortStructinLobbyUtils.cpp:ResourceGatheringManager::removeSupplyCenter,removeSupplyWarehousestd::eraseby object IDWeaponTemplate::trimTriggeredHistoricDamagestd::erase_if(..., HistoricDamageHasTriggerId)Eva::processPlayingMessagesstd::erase_if(..., EvaCheckIsFinished), with the two original conditions and commentsEva::resetm_checks.clear()(the loop erased every element)Squad::getLiveObjectsstd::erase_if(..., ObjectIsNotSelectable)JetAIUpdate::pruneDeadTargetersstd::erase_if(..., ObjectIDIsGone)CommandXlatselect-team (Core)std::erase_if(..., DrawableIsNotLocallyControlled)Loops left as they are:
deleteOverrides(),resetWakeFrame(),createSpawn()orleaveGroup(), deal damage, update a counter or flag, or move the element to another list. This covers Credits, ControlBarResizer, GameWindowTransitions, HeaderTemplate, ShellMenuScheme, Player, CampaignManager, InGameUI, MilesAudioManager, CrateSystem, RankInfo, Science, SpecialPower, ParkingPlace, FlightDeck, Countermeasures, SpawnBehavior, OpenContain, AIGroup,Squad::getAllObjectsandWeaponStore::update.ResourceGatheringManager::findBestSupplyWarehouse/findBestSupplyCenter: the same loop also picks the best dock, and splitting it would look up each object twice.WeaponTemplate::trimOldHistoricDamage: it stops at the first entry it keeps.ThingTemplate:clearAiModuleInfo's element typeModuleInfo::Nuggetis private; the other three loops also record what they cleared.DiscreteCircle::removeDuplicates: it compares neighbours, so it is aunique, not anerase_if.GameLogicm_normalUpdatesandW3DTerrainVisual::updateSeismicSimulations: only compiled withALLOW_NONSLEEPY_UPDATESandDO_SEISMIC_SIMULATIONS, which nothing defines.Evidence
Disassembly: ClangCL and VC6 Release objects for both games were compared function by function against
main. In every changed function the float arithmetic matchesmain. Call targets match apart from the newremove_if/erase_if/erasehelpers and templates that were inlined before and are now called out of line.removeSupplyCenter,removeSupplyWarehouselist::remove_if(37 → 55 instructions)trimTriggeredHistoricDamagelist::remove_ifWeaponTemplate::privateFireWeapon__LINE__constant changesEva::resetclear(); the per-elementmemmoveis goneclear()(65 → 47 instructions)Eva::processPlayingMessagesremove_ifon the vectorerase_ifinlined; calls the predicate andvector::erasewhere it called__copySquad::getLiveObjects,aiGroupFromSquad(inlines it)remove_ifon the vector; it calls the predicate from two places (find the first match, then compact), and still tests each element oncevector::erase,__copy_ptrsand the hash-mapfindare now called out of line instead of inlinedJetAIUpdate::pruneDeadTargeters,update(inlines it)list::remove_ifout of lineerase_ifout of line; it calls the hash-mapfind, where the old loops called_M_find(pruneDeadTargeters) orfindObjectByID(update)CommandXlat::translateGameMessagelist::remove_ifTheTacticalView->isUserControlLocked()check is duplicated into a second pathThe remaining elements keep their order in every function, so the game state and CRC should not change.
Council review
Rounds: 2
Gemini 4 Carbon could not run in round 2 because its usage limit was reached.