CodeQL 8: perf: replace ContainsKey+indexer with TryGetValue#196
CodeQL 8: perf: replace ContainsKey+indexer with TryGetValue#196rlorenzo wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Bundle ReportBundle size has no change ✅ |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #196 +/- ##
==========================================
- Coverage 42.96% 42.96% -0.01%
==========================================
Files 877 877
Lines 51468 51469 +1
Branches 4802 4802
==========================================
Hits 22113 22113
- Misses 28831 28832 +1
Partials 524 524
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Summary
Closes ~14 of 18
cs/inefficient-containskeyalerts by replacingContainsKey + indexer(two dictionary lookups) withTryGetValue(one lookup) in C# and dropping the redundantContainsKeyguard in Razor views.Changes
C# (3 files, 4 sites)
RotationsController.cs:498-511- threepersonData.ContainsKey(i.MothraId) ? personData[i.MothraId].XXX : "Unknown"ternaries collapsed into oneTryGetValue(out var p)plus threep?.XXX ?? "Unknown"expressions.RAPSAuditService.cs:153-ContainsKey(key) + indexer→TryGetValue(key, out var moreRecentActions).VMACSExport.cs:303, 345- same pattern in two helpers.Razor views (4 files, 10 sites)
Pattern
ViewData.ContainsKey("X") && (bool)(ViewData["X"] ?? false)collapsed to(bool)(ViewData["X"] ?? false)-ViewData[]already returnsnullon miss, so theContainsKeyguard is redundant once the?? falseis present. Touches:Areas/RAPS/Views/Members/List.cshtml(×4)Areas/RAPS/Views/Members/Roles.cshtml(×1)Areas/RAPS/Views/Roles/Members.cshtml(×1)Areas/RAPS/Views/Roles/Templates.cshtml(×4)Not addressed: 1
test/Students/EmergencyContactControllerTests.cs:319site (test infrastructure) and 3 likely already covered or out-of-scope.Context
Eighth in the
CodeQL N:cleanup series.Test plan
npm run test:backend- 1946 tests passing