Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion eth/downloader/statesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ func (d *Downloader) runStateSync(s *stateSync) *stateSync {

// Send the next finished request to the current sync:
case deliverReqCh <- deliverReq:
finished = append(finished[:0], finished[1:]...)
// Shift out the first request, but also set the emptied slot to nil for GC
copy(finished, finished[1:])
finished[len(finished)-1] = nil
finished = finished[:len(finished)-1]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the same effect using

finished = append(finished[:0:len(finished)-1], finished[1:]...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this full format seems to reduce the capacity too, meaning it would be a reallocation of the underlying buffer. Am I missing something?

Copy link
Copy Markdown
Contributor

@fjl fjl Dec 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested this because I thought you want to avoid growing the slice indefinitely. The threeway slice expression does this.

If all you want is setting the unused element to nil, your solution is OK.

It's hard to decide, I want to keep the code compact. This operation isn't worth three lines + comment.


// Handle incoming state packs:
case pack := <-d.stateCh:
Expand Down