Skip to content

Commit

Permalink
Merge pull request google#6 from tidwall/patch-mark-gc
Browse files Browse the repository at this point in the history
set removed items to nil
  • Loading branch information
gconnell committed May 24, 2016
2 parents 00edb8c + 9cda4e3 commit 7d79101
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (s *items) insertAt(index int, item Item) {
// back.
func (s *items) removeAt(index int) Item {
item := (*s)[index]
(*s)[index] = nil
copy((*s)[index:], (*s)[index+1:])
*s = (*s)[:len(*s)-1]
return item
Expand All @@ -146,7 +147,9 @@ func (s *items) removeAt(index int) Item {
// pop removes and returns the last element in the list.
func (s *items) pop() (out Item) {
index := len(*s) - 1
out, *s = (*s)[index], (*s)[:index]
out = (*s)[index]
(*s)[index] = nil
*s = (*s)[:index]
return
}

Expand Down Expand Up @@ -180,6 +183,7 @@ func (s *children) insertAt(index int, n *node) {
// back.
func (s *children) removeAt(index int) *node {
n := (*s)[index]
(*s)[index] = nil
copy((*s)[index:], (*s)[index+1:])
*s = (*s)[:len(*s)-1]
return n
Expand All @@ -188,7 +192,9 @@ func (s *children) removeAt(index int) *node {
// pop removes and returns the last element in the list.
func (s *children) pop() (out *node) {
index := len(*s) - 1
out, *s = (*s)[index], (*s)[:index]
out = (*s)[index]
(*s)[index] = nil
*s = (*s)[:index]
return
}

Expand Down

0 comments on commit 7d79101

Please sign in to comment.