add usable_space to DatabaseHeader

we already have the `DatabaseHeader`, we don't need the cached result
This commit is contained in:
Levy A.
2025-07-22 16:26:45 -03:00
parent e35fdb8263
commit fe66c61ff5
2 changed files with 5 additions and 1 deletions

View File

@@ -1422,7 +1422,7 @@ impl Pager {
// Reserve 2 slots for the trunk page header which is 8 bytes or 2*LEAF_ENTRY_SIZE
let max_free_list_entries =
(self.usable_space() / LEAF_ENTRY_SIZE) - RESERVED_SLOTS;
(header.usable_space() / LEAF_ENTRY_SIZE) - RESERVED_SLOTS;
if number_of_leaf_pages < max_free_list_entries as u32 {
turso_assert!(

View File

@@ -276,6 +276,10 @@ impl DatabaseHeader {
const _CHECK: () = {
assert!(Self::SIZE == 100);
};
pub fn usable_space(self) -> usize {
(self.page_size.get() as usize) - (self.reserved_space as usize)
}
}
impl Default for DatabaseHeader {