-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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
all: assign zero after resize in implementations of heap.Interface #26296
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -508,6 +508,7 @@ func (s *TxByPriceAndTime) Pop() interface{} { | |
old := *s | ||
n := len(old) | ||
x := old[n-1] | ||
old[n-1] = nil | ||
*s = old[0 : n-1] | ||
Comment on lines
+511
to
512
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting idea -- but I think this should not be needed. Instead of nilling the item, we resize the slice. Taken to the extreme, imagine we have a slice with 100 pointers, and then do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think resizing would help since the same underlying array is referenced. This is the example for a priority queue from the standard lib:
|
||
return x | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ func (h *expHeap) Pop() interface{} { | |
old := *h | ||
n := len(old) | ||
x := old[n-1] | ||
old[n-1] = expItem{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this is moot, and will be forgotten by the next line |
||
*h = old[0 : n-1] | ||
return x | ||
} |
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.
Setting a
uint64
to0
does not make any difference to the gcThere 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.
Slice tricks from the Go wiki states that you should set the item that is deleted to the zero value of T.
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.
Interesting!