perf(node, p2p): avoid unnecessary check len of map#1995
perf(node, p2p): avoid unnecessary check len of map#1995AnilChinchawale merged 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 You can disable this status message by setting the
✨ 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 |
There was a problem hiding this comment.
Pull request overview
Removes redundant len(map) > 0 guards before blacklist membership checks, relying on Go’s safe lookup behavior for nil/empty maps.
Changes:
- Simplified blacklist rejection in inbound connection setup (
p2p/server.go). - Simplified blacklist rejection in admin RPC peer-add flows (
node/api.go).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| p2p/server.go | Removes the len(srv.BlackPeers) > 0 wrapper and performs direct blacklist lookup during connection setup. |
| node/api.go | Removes len(server.BlackPeers) > 0 wrappers and performs direct blacklist lookup in AddPeer and AddTrustedPeer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
len(map)len(map)
0be23fb to
0d22d61
Compare
len(map)0d22d61 to
a9b4618
Compare
Proposed changes
Even if the map is not initialized, we can use map[key] to check if the key is in map directly.
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which part of the codebase this PR will touch base on,
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