Small perf: find() instead of filter() for retreat#3277
Conversation
…at, since we just need the first hit
WalkthroughRefactored array-based attack lookup in PlayerImpl by replacing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/core/game/PlayerImpl.ts (1)
369-369: Optional: rename the callback parameter to avoid shadowing the outerattack.In both methods, the arrow-function parameter is named
attack, which shadows theconst attackbeing declared on the same line. It resolves correctly, but renaming it removes the visual confusion.♻️ Suggested rename
- const attack = this._outgoingAttacks.find((attack) => attack.id() === id); + const attack = this._outgoingAttacks.find((a) => a.id() === id);Apply the same change on both line 369 and line 377.
Also applies to: 377-377
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/core/game/PlayerImpl.ts` at line 369, The local constant named attack is being shadowed by the arrow-function parameter in the calls to this._outgoingAttacks.find; update the callback parameter name (e.g., change (attack) => to (outgoing) => or (atk) =>) in the find invocations so the outer const attack refers to the found item without visual shadowing—apply the same rename in both occurrences where this._outgoingAttacks.find is used (the lines creating the const attack and the second similar find).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/core/game/PlayerImpl.ts`:
- Line 369: The local constant named attack is being shadowed by the
arrow-function parameter in the calls to this._outgoingAttacks.find; update the
callback parameter name (e.g., change (attack) => to (outgoing) => or (atk) =>)
in the find invocations so the outer const attack refers to the found item
without visual shadowing—apply the same rename in both occurrences where
this._outgoingAttacks.find is used (the lines creating the const attack and the
second similar find).
Description:
Only need find() instead of filter() in orderRetreat and executeRetreat, since we just need the first hit. Small perf win.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
tryout33