ScopeContextAsyncState - Refactor to reduce code complexity#6041
ScopeContextAsyncState - Refactor to reduce code complexity#6041
Conversation
WalkthroughRefactored async scope-capture logic in Changes
Sequence Diagram(s)sequenceDiagram
participant Capture as CaptureRoutine
participant Ensure as EnsureUniqueProperties
participant Clone as CloneNestedContext
rect rgba(200,230,201,0.45)
Capture->>Ensure: properties (IList / null)
Ensure-->>Capture: null / same dict / new Dictionary (<=10)
end
rect rgba(187,222,251,0.45)
Capture->>Clone: nestedContext (IList<object>)
Clone-->>Capture: object[] (copied)
end
Note right of Capture: Unified control flow uses Ensure result and cloned array
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)src/NLog/Internal/ScopeContextAsyncState.cs (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (1)
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 |
4b0d2ef to
bf6d8c3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/NLog/Internal/ScopeContextAsyncState.cs(7 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/NLog/Internal/ScopeContextAsyncState.cs (2)
src/NLog/ScopeContext.cs (9)
Dictionary(496-514)Dictionary(732-746)Dictionary(749-756)Dictionary(778-789)Dictionary(828-831)ScopeContext(55-896)ScopeContextPropertyEnumerator(269-272)IList(346-351)IList(353-356)src/NLog/Internal/ScopeContextPropertyEnumerator.cs (3)
ScopeContextPropertyEnumerator(47-80)HasUniqueCollectionKeys(96-137)CopyScopePropertiesToDictionary(83-93)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: task-list-completed
🔇 Additional comments (4)
src/NLog/Internal/ScopeContextAsyncState.cs (4)
298-324: LGTM! Clean simplification of control flow.The removal of unnecessary braces and flattening of nested conditionals improves readability while maintaining the same logic. The early-return pattern is clearer.
378-386: LGTM! Effective flattening of nested conditionals.The refactored code reduces nesting depth and uses clearer early-return patterns, making the control flow easier to follow while preserving the original behavior.
542-542: LGTM! Good extraction of common array cloning logic.The new
CloneNestedContexthelper eliminates code duplication and provides a clear, reusable method for copying nested context arrays. All call sites properly handle null cases before invoking the helper.Also applies to: 556-556, 566-572
139-154: Well-structured refactoring with clear early-return pattern.The refactored
EnsureUniquePropertiesmethod with early returns for trivial cases (count <= 1, already-unique dictionary) is more readable than the previous implementation. The consolidated duplicate-checking logic is clearer. Apart from the potential type-matching concern flagged separately, this is a solid improvement.
bf6d8c3 to
3555dbc
Compare
|



No description provided.