Skip to content

Commit

Permalink
rename cell_get_raw_pointer_region() and refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jussisaurio committed Dec 24, 2024
1 parent 25338b5 commit 42ea904
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 4 additions & 7 deletions core/storage/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ impl BTreeCursor {
buf[new_cell_data_pointer as usize..new_cell_data_pointer as usize + payload.len()]
.copy_from_slice(payload);
// memmove(pIns+2, pIns, 2*(pPage->nCell - i));
let (cell_pointer_array_start, _) = page.cell_get_raw_pointer_region();
let (cell_pointer_array_start, _) = page.cell_pointer_array_offset_and_size();
let cell_pointer_cur_idx = cell_pointer_array_start + (CELL_POINTER_SIZE_BYTES * cell_idx);

// move existing pointers forward by CELL_POINTER_SIZE_BYTES...
Expand Down Expand Up @@ -1232,7 +1232,7 @@ impl BTreeCursor {
if is_page_1 {
// Remove header from child and set offset to 0
let contents = child.get().contents.as_mut().unwrap();
let (cell_pointer_offset, _) = contents.cell_get_raw_pointer_region();
let (cell_pointer_offset, _) = contents.cell_pointer_array_offset_and_size();
// change cell pointers
for cell_idx in 0..contents.cell_count() {
let cell_pointer_offset = cell_pointer_offset + (2 * cell_idx) - offset;
Expand Down Expand Up @@ -1288,7 +1288,7 @@ impl BTreeCursor {
fn allocate_cell_space(&self, page_ref: &PageContent, amount: u16) -> u16 {
let amount = amount as usize;

let (cell_offset, _) = page_ref.cell_get_raw_pointer_region();
let (cell_offset, _) = page_ref.cell_pointer_array_offset_and_size();
let gap = cell_offset + 2 * page_ref.cell_count();
let mut top = page_ref.cell_content_area() as usize;

Expand Down Expand Up @@ -1330,10 +1330,7 @@ impl BTreeCursor {
// TODO: implement fast algorithm

let last_cell = usable_space - 4;
let first_cell = {
let (start, end) = cloned_page.cell_get_raw_pointer_region();
start + end
};
let first_cell = cloned_page.unallocated_region_start() as u64;

if cloned_page.cell_count() > 0 {
let page_type = page.page_type();
Expand Down
9 changes: 5 additions & 4 deletions core/storage/sqlite3_ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ impl PageContent {
/// The start of the unallocated region.
/// Effectively: the offset after the page header + the cell pointer array.
pub fn unallocated_region_start(&self) -> usize {
self.offset + self.header_size() + self.cell_pointer_array_size()
let (cell_ptr_array_start, cell_ptr_array_size) = self.cell_pointer_array_offset_and_size();
cell_ptr_array_start + cell_ptr_array_size
}

pub fn unallocated_region_size(&self) -> usize {
Expand Down Expand Up @@ -576,9 +577,9 @@ impl PageContent {
/// The cell pointers are arranged in key order with:
/// - left-most cell (the cell with the smallest key) first and
/// - the right-most cell (the cell with the largest key) last.
pub fn cell_get_raw_pointer_region(&self) -> (usize, usize) {
let cell_start = self.header_size();
(self.offset + cell_start, self.cell_count() * 2)
pub fn cell_pointer_array_offset_and_size(&self) -> (usize, usize) {
let header_size = self.header_size();
(self.offset + header_size, self.cell_pointer_array_size())
}

/* Get region of a cell's payload */
Expand Down

0 comments on commit 42ea904

Please # to comment.