-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix remove connecting list bug #361
Conversation
p2pserver/net/netserver/netserver.go
Outdated
addrs = append(this.ConnectingAddrs[:i], this.ConnectingAddrs[i+1:]...) | ||
for _, a := range this.ConnectingAddrs { | ||
if strings.Compare(a, addr) != 0 { | ||
addrs = append(addrs, a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use this.ConnectingAddrs = append(this.ConnectingAddrs[:i], this.ConnectingAddrs[i+1:]...), instead of using temp variable addrs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if you change the this.ConnectingAddrs which is used for loop, it is dangerous. And in this case, it also can not remove duplicated elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. So please use addrs := this.ConnectingAddrs[:0] to avoid allocating a new underlying array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw: you can use if a != addr
directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, thanks all
Signed-off-by: chenzhijie <chenzhijie@onchain.com>
Signed-off-by: chenzhijie <chenzhijie@onchain.com>
Signed-off-by: chenzhijie <chenzhijie@onchain.com>
Signed-off-by: chenzhijie chenzhijie@onchain.com