Fix freelist.size calculation for large freelists

freelist.size did not account for the extra
fake freelist item used to hold the number of
elements when the freelist is large.
master
Josh Bleecher Snyder 2016-12-22 17:22:44 -08:00
parent 0e120dc470
commit 7adfa44e02
1 changed files with 6 additions and 1 deletions

View File

@ -24,7 +24,12 @@ func newFreelist() *freelist {
// size returns the size of the page after serialization.
func (f *freelist) size() int {
return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * f.count())
n := f.count()
if n >= 0xFFFF {
// The first element will be used to store the count. See freelist.write.
n++
}
return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * n)
}
// count returns count of pages on the freelist