Skip to content
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

Merged
merged 2 commits into from
Jun 19, 2018
Merged

fix remove connecting list bug #361

merged 2 commits into from
Jun 19, 2018

Conversation

chenzhijie
Copy link
Contributor

Signed-off-by: chenzhijie chenzhijie@onchain.com

addrs = append(this.ConnectingAddrs[:i], this.ConnectingAddrs[i+1:]...)
for _, a := range this.ConnectingAddrs {
if strings.Compare(a, addr) != 0 {
addrs = append(addrs, a)
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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>
@laizy laizy merged commit 765b337 into ontio:master Jun 19, 2018
BooniesFX pushed a commit to BooniesFX/ontology that referenced this pull request Jun 20, 2018
Signed-off-by: chenzhijie <chenzhijie@onchain.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants