perf(core/txpool/legacypool): use maps.Keys and maps.Copy #30091#2165
perf(core/txpool/legacypool): use maps.Keys and maps.Copy #30091#2165gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL 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)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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.
Pull request overview
This PR updates core/txpool/legacypool to use Go’s maps helpers to simplify set flattening and merging logic inside the legacy transaction pool.
Changes:
- Replace manual key-collection loop with
maps.Keys+slices.CollectinaccountSet.flatten. - Replace manual merge loop with
maps.CopyinaccountSet.merge.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for account := range as.accounts { | ||
| accounts = append(accounts, account) | ||
| } | ||
| accounts := slices.Collect(maps.Keys(as.accounts)) |
There was a problem hiding this comment.
flatten previously always returned a non-nil empty slice when the set was empty (due to make([]T, 0, ...)). With slices.Collect(maps.Keys(...)), the result will be nil when as.accounts is empty, which can be an observable behavior change (e.g., JSON encoding null vs [], or callers comparing to []common.Address{}). Consider ensuring accounts is initialized to an empty (non-nil) slice when there are zero keys to preserve the previous behavior.
| accounts := slices.Collect(maps.Keys(as.accounts)) | |
| accounts := slices.Collect(maps.Keys(as.accounts)) | |
| if accounts == nil { | |
| accounts = make([]common.Address, 0) | |
| } |
8c3a618 to
ec362f1
Compare
Proposed changes
Ref: ethereum#30091
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which parts of the codebase does this PR touch?
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that