core/vdbe: Unify B-Tree cursors

This commit is contained in:
Pekka Enberg
2025-03-04 14:34:12 +02:00
parent 1c0d9c3b46
commit cdcaebb878
2 changed files with 13 additions and 25 deletions

View File

@@ -619,20 +619,15 @@ impl Record {
}
pub enum Cursor {
Table(BTreeCursor),
Index(BTreeCursor),
BTree(BTreeCursor),
Pseudo(PseudoCursor),
Sorter(Sorter),
Virtual(VTabOpaqueCursor),
}
impl Cursor {
pub fn new_table(cursor: BTreeCursor) -> Self {
Self::Table(cursor)
}
pub fn new_index(cursor: BTreeCursor) -> Self {
Self::Index(cursor)
pub fn new_btree(cursor: BTreeCursor) -> Self {
Self::BTree(cursor)
}
pub fn new_pseudo(cursor: PseudoCursor) -> Self {
@@ -643,17 +638,10 @@ impl Cursor {
Self::Sorter(cursor)
}
pub fn as_table_mut(&mut self) -> &mut BTreeCursor {
pub fn as_btree_mut(&mut self) -> &mut BTreeCursor {
match self {
Self::Table(cursor) => cursor,
_ => panic!("Cursor is not a table"),
}
}
pub fn as_index_mut(&mut self) -> &mut BTreeCursor {
match self {
Self::Index(cursor) => cursor,
_ => panic!("Cursor is not an index"),
Self::BTree(cursor) => cursor,
_ => panic!("Cursor is not a btree"),
}
}

View File

@@ -295,7 +295,7 @@ impl ProgramState {
.expect("cursor id out of bounds")
.as_mut()
.expect("cursor not allocated")
.as_table_mut();
.as_btree_mut();
unsafe { std::mem::transmute(cursor) }
}
@@ -306,7 +306,7 @@ impl ProgramState {
.expect("cursor id out of bounds")
.as_mut()
.expect("cursor not allocated")
.as_index_mut();
.as_btree_mut();
unsafe { std::mem::transmute(cursor) }
}
@@ -770,13 +770,13 @@ impl Program {
cursors
.get_mut(*cursor_id)
.unwrap()
.replace(Cursor::new_table(cursor));
.replace(Cursor::new_btree(cursor));
}
CursorType::BTreeIndex(_) => {
cursors
.get_mut(*cursor_id)
.unwrap()
.replace(Cursor::new_index(cursor));
.replace(Cursor::new_btree(cursor));
}
CursorType::Pseudo(_) => {
panic!("OpenReadAsync on pseudo cursor");
@@ -1285,7 +1285,7 @@ impl Program {
}
}
let mut cursors = state.cursors.borrow_mut();
if let Some(Cursor::Table(btree_cursor)) = cursors.get_mut(*cursor_id).unwrap()
if let Some(Cursor::BTree(btree_cursor)) = cursors.get_mut(*cursor_id).unwrap()
{
if let Some(ref rowid) = btree_cursor.rowid()? {
state.registers[*dest] = OwnedValue::Integer(*rowid as i64);
@@ -2826,12 +2826,12 @@ impl Program {
cursors
.get_mut(*cursor_id)
.unwrap()
.replace(Cursor::new_index(cursor));
.replace(Cursor::new_btree(cursor));
} else {
cursors
.get_mut(*cursor_id)
.unwrap()
.replace(Cursor::new_table(cursor));
.replace(Cursor::new_btree(cursor));
}
state.pc += 1;
}