mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-16 05:24:22 +01:00
sqlite3_ondisk: generalize left-child-pointer reading function to both index/table btrees
This commit is contained in:
@@ -1362,8 +1362,8 @@ impl BTreeCursor {
|
||||
let max = max_cell_idx.get();
|
||||
if min > max {
|
||||
if let Some(nearest_matching_cell) = nearest_matching_cell.get() {
|
||||
let left_child_page = contents
|
||||
.cell_table_interior_read_left_child_page(nearest_matching_cell)?;
|
||||
let left_child_page =
|
||||
contents.cell_interior_read_left_child_page(nearest_matching_cell);
|
||||
self.stack.set_cell_index(nearest_matching_cell as i32);
|
||||
let mem_page = self.read_page(left_child_page as usize)?;
|
||||
self.stack.push(mem_page);
|
||||
|
||||
@@ -582,21 +582,24 @@ impl PageContent {
|
||||
Ok(rowid as i64)
|
||||
}
|
||||
|
||||
/// Read the left child page of a table interior cell.
|
||||
/// Read the left child page of a table interior cell or an index interior cell.
|
||||
#[inline(always)]
|
||||
pub fn cell_table_interior_read_left_child_page(&self, idx: usize) -> Result<u32> {
|
||||
debug_assert!(self.page_type() == PageType::TableInterior);
|
||||
pub fn cell_interior_read_left_child_page(&self, idx: usize) -> u32 {
|
||||
debug_assert!(
|
||||
self.page_type() == PageType::TableInterior
|
||||
|| self.page_type() == PageType::IndexInterior
|
||||
);
|
||||
let buf = self.as_ptr();
|
||||
const INTERIOR_PAGE_HEADER_SIZE_BYTES: usize = 12;
|
||||
let cell_pointer_array_start = INTERIOR_PAGE_HEADER_SIZE_BYTES;
|
||||
let cell_pointer = cell_pointer_array_start + (idx * 2);
|
||||
let cell_pointer = self.read_u16(cell_pointer) as usize;
|
||||
Ok(u32::from_be_bytes([
|
||||
u32::from_be_bytes([
|
||||
buf[cell_pointer],
|
||||
buf[cell_pointer + 1],
|
||||
buf[cell_pointer + 2],
|
||||
buf[cell_pointer + 3],
|
||||
]))
|
||||
])
|
||||
}
|
||||
|
||||
/// Read the rowid of a table leaf cell.
|
||||
|
||||
Reference in New Issue
Block a user