| 285 | } |
| 286 | |
| 287 | func (t *shared) Write(p *common.Page) { |
| 288 | // Combine the old free pgids and pgids waiting on an open transaction. |
| 289 | |
| 290 | // Update the header flag. |
| 291 | p.SetFlags(common.FreelistPageFlag) |
| 292 | |
| 293 | // The page.count can only hold up to 64k elements so if we overflow that |
| 294 | // number then we handle it by putting the size in the first element. |
| 295 | l := t.Count() |
| 296 | if l == 0 { |
| 297 | p.SetCount(uint16(l)) |
| 298 | } else if l < 0xFFFF { |
| 299 | p.SetCount(uint16(l)) |
| 300 | data := common.UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)) |
| 301 | ids := unsafe.Slice((*common.Pgid)(data), l) |
| 302 | t.Copyall(ids) |
| 303 | } else { |
| 304 | p.SetCount(0xFFFF) |
| 305 | data := common.UnsafeAdd(unsafe.Pointer(p), unsafe.Sizeof(*p)) |
| 306 | ids := unsafe.Slice((*common.Pgid)(data), l+1) |
| 307 | ids[0] = common.Pgid(l) |
| 308 | t.Copyall(ids[1:]) |
| 309 | } |
| 310 | } |