@@ -74,19 +74,27 @@ func (p *Page) IsFreelistPage() bool {
7474 return p .flags == FreelistPageFlag
7575}
7676
77+ // IsValidPage checks Page flags correctness, only a single proper flag can be used.
78+ func (p * Page ) IsValidPage () bool {
79+ return p .IsBranchPage () ||
80+ p .IsLeafPage () ||
81+ p .IsMetaPage () ||
82+ p .IsFreelistPage ()
83+ }
84+
7785// Meta returns a pointer to the metadata section of the page.
7886func (p * Page ) Meta () * Meta {
7987 return (* Meta )(UnsafeAdd (unsafe .Pointer (p ), unsafe .Sizeof (* p )))
8088}
8189
8290func (p * Page ) FastCheck (id Pgid ) {
83- Assert (p .id == id , "Page expected to be: %v, but self identifies as %v" , id , p .id )
91+ if p .id != id {
92+ panic (fmt .Sprintf ("assertion failed: Page expected to be: %v, but self identifies as %v" , id , p .id ))
93+ }
8494 // Only one flag of page-type can be set.
85- Assert (p .IsBranchPage () ||
86- p .IsLeafPage () ||
87- p .IsMetaPage () ||
88- p .IsFreelistPage (),
89- "page %v: has unexpected type/flags: %x" , p .id , p .flags )
95+ if ! p .IsValidPage () {
96+ panic (fmt .Sprintf ("assertion failed: page %v: has unexpected type/flags: %x" , p .id , p .flags ))
97+ }
9098}
9199
92100// LeafPageElement retrieves the leaf node by index
@@ -122,7 +130,9 @@ func (p *Page) BranchPageElements() []branchPageElement {
122130}
123131
124132func (p * Page ) FreelistPageCount () (int , int ) {
125- Assert (p .IsFreelistPage (), fmt .Sprintf ("can't get freelist page count from a non-freelist page: %2x" , p .flags ))
133+ if ! p .IsFreelistPage () {
134+ panic (fmt .Sprintf ("assertion failed: can't get freelist page count from a non-freelist page: %2x" , p .flags ))
135+ }
126136
127137 // If the page.count is at the max uint16 value (64k) then it's considered
128138 // an overflow and the size of the freelist is stored as the first element.
@@ -140,7 +150,9 @@ func (p *Page) FreelistPageCount() (int, int) {
140150}
141151
142152func (p * Page ) FreelistPageIds () []Pgid {
143- Assert (p .IsFreelistPage (), fmt .Sprintf ("can't get freelist page IDs from a non-freelist page: %2x" , p .flags ))
153+ if ! p .IsFreelistPage () {
154+ panic (fmt .Sprintf ("assertion failed: can't get freelist page IDs from a non-freelist page: %2x" , p .flags ))
155+ }
144156
145157 idx , count := p .FreelistPageCount ()
146158
0 commit comments