This repository was archived by the owner on Mar 9, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -166,12 +166,16 @@ func (f *freelist) read(p *page) {
166
166
}
167
167
168
168
// Copy the list of page ids from the freelist.
169
- ids := ((* [maxAllocSize ]pgid )(unsafe .Pointer (& p .ptr )))[idx :count ]
170
- f .ids = make ([]pgid , len (ids ))
171
- copy (f .ids , ids )
169
+ if count == 0 {
170
+ f .ids = nil
171
+ } else {
172
+ ids := ((* [maxAllocSize ]pgid )(unsafe .Pointer (& p .ptr )))[idx :count ]
173
+ f .ids = make ([]pgid , len (ids ))
174
+ copy (f .ids , ids )
172
175
173
- // Make sure they're sorted.
174
- sort .Sort (pgids (f .ids ))
176
+ // Make sure they're sorted.
177
+ sort .Sort (pgids (f .ids ))
178
+ }
175
179
176
180
// Rebuild the page cache.
177
181
f .reindex ()
@@ -189,7 +193,9 @@ func (f *freelist) write(p *page) error {
189
193
190
194
// The page.count can only hold up to 64k elements so if we overflow that
191
195
// number then we handle it by putting the size in the first element.
192
- if len (ids ) < 0xFFFF {
196
+ if len (ids ) == 0 {
197
+ p .count = uint16 (len (ids ))
198
+ } else if len (ids ) < 0xFFFF {
193
199
p .count = uint16 (len (ids ))
194
200
copy (((* [maxAllocSize ]pgid )(unsafe .Pointer (& p .ptr )))[:], ids )
195
201
} else {
Original file line number Diff line number Diff line change @@ -201,6 +201,11 @@ func (n *node) write(p *page) {
201
201
}
202
202
p .count = uint16 (len (n .inodes ))
203
203
204
+ // Stop here if there are no items to write.
205
+ if p .count == 0 {
206
+ return
207
+ }
208
+
204
209
// Loop over each item and write it to the page.
205
210
b := (* [maxAllocSize ]byte )(unsafe .Pointer (& p .ptr ))[n .pageElementSize ()* len (n .inodes ):]
206
211
for i , item := range n .inodes {
Original file line number Diff line number Diff line change @@ -62,6 +62,9 @@ func (p *page) leafPageElement(index uint16) *leafPageElement {
62
62
63
63
// leafPageElements retrieves a list of leaf nodes.
64
64
func (p * page ) leafPageElements () []leafPageElement {
65
+ if p .count == 0 {
66
+ return nil
67
+ }
65
68
return ((* [0x7FFFFFF ]leafPageElement )(unsafe .Pointer (& p .ptr )))[:]
66
69
}
67
70
@@ -72,6 +75,9 @@ func (p *page) branchPageElement(index uint16) *branchPageElement {
72
75
73
76
// branchPageElements retrieves a list of branch nodes.
74
77
func (p * page ) branchPageElements () []branchPageElement {
78
+ if p .count == 0 {
79
+ return nil
80
+ }
75
81
return ((* [0x7FFFFFF ]branchPageElement )(unsafe .Pointer (& p .ptr )))[:]
76
82
}
77
83
You can’t perform that action at this time.
0 commit comments