From f945795ae6e8dcdfa9f5e217aef6222f36fc0888 Mon Sep 17 00:00:00 2001 From: jussisaurio Date: Mon, 18 Nov 2024 18:29:23 +0200 Subject: [PATCH] consistent naming --- core/storage/btree.rs | 24 +++++++++++------------ core/vdbe/mod.rs | 44 ++++++++++++++++--------------------------- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/core/storage/btree.rs b/core/storage/btree.rs index b09943208..b3298ecc4 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -39,7 +39,7 @@ const BTREE_HEADER_OFFSET_RIGHTMOST: usize = 8; /* if internalnode, pointer righ pub const BTCURSOR_MAX_DEPTH: usize = 20; /// Evaluate a Result>, if IO return IO. -macro_rules! return_on_io { +macro_rules! return_if_io { ($expr:expr) => { match $expr? { CursorResult::Ok(v) => v, @@ -395,7 +395,7 @@ impl BTreeCursor { key: SeekKey<'_>, op: SeekOp, ) -> Result, Option)>> { - return_on_io!(self.move_to(key.clone(), op.clone())); + return_if_io!(self.move_to(key.clone(), op.clone())); { let page_rc = self.stack.top(); @@ -699,7 +699,7 @@ impl BTreeCursor { WriteState::BalanceStart | WriteState::BalanceMoveUp | WriteState::BalanceGetParentPage => { - return_on_io!(self.balance_leaf()); + return_if_io!(self.balance_leaf()); } WriteState::Finish => { self.write_info.state = WriteState::Start; @@ -1689,10 +1689,10 @@ fn find_free_cell(page_ref: &PageContent, db_header: Ref, amount impl Cursor for BTreeCursor { fn seek_to_last(&mut self) -> Result> { - return_on_io!(self.move_to_rightmost()); - let (rowid, record) = return_on_io!(self.get_next_record(None)); + return_if_io!(self.move_to_rightmost()); + let (rowid, record) = return_if_io!(self.get_next_record(None)); if rowid.is_none() { - let is_empty = return_on_io!(self.is_empty_table()); + let is_empty = return_if_io!(self.is_empty_table()); assert!(is_empty); return Ok(CursorResult::Ok(())); } @@ -1708,7 +1708,7 @@ impl Cursor for BTreeCursor { fn rewind(&mut self) -> Result> { self.move_to_root(); - let (rowid, record) = return_on_io!(self.get_next_record(None)); + let (rowid, record) = return_if_io!(self.get_next_record(None)); self.rowid.replace(rowid); self.record.replace(record); Ok(CursorResult::Ok(())) @@ -1722,7 +1722,7 @@ impl Cursor for BTreeCursor { } fn next(&mut self) -> Result> { - let (rowid, record) = return_on_io!(self.get_next_record(None)); + let (rowid, record) = return_if_io!(self.get_next_record(None)); self.rowid.replace(rowid); self.record.replace(record); Ok(CursorResult::Ok(())) @@ -1749,7 +1749,7 @@ impl Cursor for BTreeCursor { } fn seek(&mut self, key: SeekKey<'_>, op: SeekOp) -> Result> { - let (rowid, record) = return_on_io!(self.seek(key, op)); + let (rowid, record) = return_if_io!(self.seek(key, op)); self.rowid.replace(rowid); self.record.replace(record); Ok(CursorResult::Ok(rowid.is_some())) @@ -1770,10 +1770,10 @@ impl Cursor for BTreeCursor { _ => unreachable!("btree tables are indexed by integers!"), }; if !moved_before { - return_on_io!(self.move_to(SeekKey::TableRowId(*int_key as u64), SeekOp::EQ)); + return_if_io!(self.move_to(SeekKey::TableRowId(*int_key as u64), SeekOp::EQ)); } - return_on_io!(self.insert_into_page(key, _record)); + return_if_io!(self.insert_into_page(key, _record)); Ok(CursorResult::Ok(())) } @@ -1790,7 +1790,7 @@ impl Cursor for BTreeCursor { OwnedValue::Integer(i) => i, _ => unreachable!("btree tables are indexed by integers!"), }; - return_on_io!(self.move_to(SeekKey::TableRowId(*int_key as u64), SeekOp::EQ)); + return_if_io!(self.move_to(SeekKey::TableRowId(*int_key as u64), SeekOp::EQ)); let page_ref = self.stack.top(); let page = page_ref.borrow(); // TODO(pere): request load diff --git a/core/vdbe/mod.rs b/core/vdbe/mod.rs index 4869a7a29..ba06eb9ae 100644 --- a/core/vdbe/mod.rs +++ b/core/vdbe/mod.rs @@ -535,7 +535,7 @@ pub enum StepResult<'a> { /// If there is I/O, the instruction is restarted. /// Evaluate a Result>, if IO return Ok(StepResult::IO). -macro_rules! return_on_io { +macro_rules! return_if_io { ($expr:expr) => { match $expr? { CursorResult::Ok(v) => v, @@ -1113,18 +1113,12 @@ impl Program { } Insn::RewindAsync { cursor_id } => { let cursor = cursors.get_mut(cursor_id).unwrap(); - return_on_io!(cursor.rewind()); + return_if_io!(cursor.rewind()); state.pc += 1; } Insn::LastAsync { cursor_id } => { let cursor = cursors.get_mut(cursor_id).unwrap(); - match cursor.last()? { - CursorResult::Ok(()) => {} - CursorResult::IO => { - // If there is I/O, the instruction is restarted. - return Ok(StepResult::IO); - } - } + return_if_io!(cursor.last()); state.pc += 1; } Insn::LastAwait { @@ -1199,19 +1193,13 @@ impl Program { Insn::NextAsync { cursor_id } => { let cursor = cursors.get_mut(cursor_id).unwrap(); cursor.set_null_flag(false); - return_on_io!(cursor.next()); + return_if_io!(cursor.next()); state.pc += 1; } Insn::PrevAsync { cursor_id } => { let cursor = cursors.get_mut(cursor_id).unwrap(); cursor.set_null_flag(false); - match cursor.prev()? { - CursorResult::Ok(_) => {} - CursorResult::IO => { - // If there is I/O, the instruction is restarted. - return Ok(StepResult::IO); - } - } + return_if_io!(cursor.prev()); state.pc += 1; } Insn::PrevAwait { @@ -1385,7 +1373,7 @@ impl Program { )); } }; - let found = return_on_io!(cursor.seek(SeekKey::TableRowId(rowid), SeekOp::EQ)); + let found = return_if_io!(cursor.seek(SeekKey::TableRowId(rowid), SeekOp::EQ)); if !found { state.pc = *target_pc; } else { @@ -1410,7 +1398,7 @@ impl Program { let cursor = cursors.get_mut(cursor_id).unwrap(); let record_from_regs: OwnedRecord = make_owned_record(&state.registers, start_reg, num_regs); - let found = return_on_io!( + let found = return_if_io!( cursor.seek(SeekKey::IndexKey(&record_from_regs), SeekOp::GE) ); if !found { @@ -1423,7 +1411,7 @@ impl Program { let rowid = match &state.registers[*start_reg] { OwnedValue::Null => { // All integer values are greater than null so we just rewind the cursor - return_on_io!(cursor.rewind()); + return_if_io!(cursor.rewind()); state.pc += 1; continue; } @@ -1435,7 +1423,7 @@ impl Program { } }; let found = - return_on_io!(cursor.seek(SeekKey::TableRowId(rowid), SeekOp::GE)); + return_if_io!(cursor.seek(SeekKey::TableRowId(rowid), SeekOp::GE)); if !found { state.pc = *target_pc; } else { @@ -1454,7 +1442,7 @@ impl Program { let cursor = cursors.get_mut(cursor_id).unwrap(); let record_from_regs: OwnedRecord = make_owned_record(&state.registers, start_reg, num_regs); - let found = return_on_io!( + let found = return_if_io!( cursor.seek(SeekKey::IndexKey(&record_from_regs), SeekOp::GT) ); if !found { @@ -1467,7 +1455,7 @@ impl Program { let rowid = match &state.registers[*start_reg] { OwnedValue::Null => { // All integer values are greater than null so we just rewind the cursor - return_on_io!(cursor.rewind()); + return_if_io!(cursor.rewind()); state.pc += 1; continue; } @@ -1479,7 +1467,7 @@ impl Program { } }; let found = - return_on_io!(cursor.seek(SeekKey::TableRowId(rowid), SeekOp::GT)); + return_if_io!(cursor.seek(SeekKey::TableRowId(rowid), SeekOp::GT)); if !found { state.pc = *target_pc; } else { @@ -1850,7 +1838,7 @@ impl Program { } => { assert!(*pc_if_next >= 0); let cursor = cursors.get_mut(cursor_id).unwrap(); - return_on_io!(cursor.next()); + return_if_io!(cursor.next()); if !cursor.is_empty() { state.pc = *pc_if_next; } else { @@ -2127,7 +2115,7 @@ impl Program { _ => unreachable!("Not a record! Cannot insert a non record value."), }; let key = &state.registers[*key_reg]; - return_on_io!(cursor.insert(key, record, true)); + return_if_io!(cursor.insert(key, record, true)); state.pc += 1; } Insn::InsertAwait { cursor_id } => { @@ -2140,7 +2128,7 @@ impl Program { } => { let cursor = cursors.get_mut(cursor).unwrap(); // TODO: make io handle rng - let rowid = return_on_io!(get_new_rowid(cursor, thread_rng())); + let rowid = return_if_io!(get_new_rowid(cursor, thread_rng())); state.registers[*rowid_reg] = OwnedValue::Integer(rowid); state.pc += 1; } @@ -2165,7 +2153,7 @@ impl Program { target_pc, } => { let cursor = cursors.get_mut(cursor).unwrap(); - let exists = return_on_io!(cursor.exists(&state.registers[*rowid_reg])); + let exists = return_if_io!(cursor.exists(&state.registers[*rowid_reg])); if exists { state.pc += 1; } else {