Merge 'Random clippy cleanups' from Pekka Enberg

Closes #253
This commit is contained in:
Pekka Enberg
2024-08-01 10:22:25 +03:00
5 changed files with 27 additions and 29 deletions

View File

@@ -467,9 +467,9 @@ impl BTreeCursor {
content with splitted page in order to not update root page idx.
*/
let new_root_page_id = new_root_page_id as u32;
payload.extend_from_slice(&(new_root_page_id as u32).to_be_bytes());
payload.extend_from_slice(&new_root_page_id.to_be_bytes());
payload.extend(std::iter::repeat(0).take(9));
let n = write_varint(&mut payload.as_mut_slice()[4..], key as u64);
let n = write_varint(&mut payload.as_mut_slice()[4..], key);
payload.truncate(4 + n);
// write left child cell
@@ -500,7 +500,7 @@ impl BTreeCursor {
// Propagate split divided to top.
payload.extend_from_slice(&(mem_page.page_idx as u32).to_be_bytes());
payload.extend(std::iter::repeat(0).take(9));
let n = write_varint(&mut payload.as_mut_slice()[4..], key as u64);
let n = write_varint(&mut payload.as_mut_slice()[4..], key);
payload.truncate(n);
self.page = RefCell::new(Some(mem_page.parent.as_ref().unwrap().clone()));
@@ -562,7 +562,7 @@ impl BTreeCursor {
/* fall through, we might need to defragment */
}
if gap + 2 + amount as usize > top {
if gap + 2 + amount > top {
// defragment
self.defragment_page(page_ref, RefCell::borrow(&self.database_header));
let mut buf_ref = RefCell::borrow_mut(&page_ref.buffer);
@@ -587,11 +587,11 @@ impl BTreeCursor {
fn defragment_page(&self, page: &PageContent, db_header: Ref<DatabaseHeader>) {
let cloned_page = page.clone();
let usable_space = (db_header.page_size - db_header.unused_space as u16) as u64;
let mut cbrk = usable_space as u64;
let mut cbrk = usable_space;
// TODO: implement fast algorithm
let last_cell = (usable_space - 4) as u64;
let last_cell = usable_space - 4;
let first_cell = {
let (start, end) = cloned_page.cell_get_raw_pointer_region();
start + end
@@ -632,7 +632,7 @@ impl BTreeCursor {
"error while parsing varint from cell, probably treat this as corruption?"
),
};
let (_, nr_key) = match read_varint(&buf[pc as usize + nr_payload as usize..]) {
let (_, nr_key) = match read_varint(&buf[pc as usize + nr_payload..]) {
Ok(v) => v,
Err(_) => todo!(
"error while parsing varint from cell, probably treat this as corruption?"
@@ -645,7 +645,7 @@ impl BTreeCursor {
PageType::IndexLeaf => todo!(),
};
cbrk -= size;
if cbrk < first_cell as u64 || pc as u64 + size > usable_space as u64 {
if cbrk < first_cell as u64 || pc + size > usable_space {
todo!("corrupt");
}
assert!(cbrk + size <= usable_space && cbrk >= first_cell as u64);
@@ -710,11 +710,11 @@ impl BTreeCursor {
// TODO: check corruption icellast
next = u16::from_be_bytes(buf[pc..pc + 2].try_into().unwrap()) as usize;
size = u16::from_be_bytes(buf[pc + 2..pc + 4].try_into().unwrap()) as usize;
nfree += size as usize;
nfree += size;
if next <= pc + size + 3 {
break;
}
pc = next as usize;
pc = next;
}
if next > 0 {
@@ -744,7 +744,7 @@ fn find_free_cell(page_ref: &PageContent, db_header: Ref<DatabaseHeader>, amount
let buf = buf_ref.as_slice();
let usable_space = (db_header.page_size - db_header.unused_space as u16) as usize;
let maxpc = (usable_space - amount as usize) as usize;
let maxpc = (usable_space - amount);
let mut found = false;
while pc <= maxpc {
let next = u16::from_be_bytes(buf[pc..pc + 2].try_into().unwrap());

View File

@@ -143,9 +143,7 @@ impl File for DarwinFile {
if lock_result == -1 {
let err = std::io::Error::last_os_error();
if err.kind() == std::io::ErrorKind::WouldBlock {
return Err(LimboError::LockingError(format!(
"Failed locking file. File is locked by another process"
)));
return Err(LimboError::LockingError("Failed locking file. File is locked by another process".to_string()));
} else {
return Err(LimboError::LockingError(format!(
"Failed locking file, {}",

View File

@@ -298,11 +298,11 @@ impl PageContent {
}
pub fn cell_content_area(&self) -> u16 {
self.read_u16(5) as u16
self.read_u16(5)
}
pub fn num_frag_free_bytes(&self) -> u8 {
self.read_u8(7) as u8
self.read_u8(7)
}
pub fn rightmost_pointer(&self) -> Option<u32> {

View File

@@ -518,7 +518,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
*start_offset as i32,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::EndCoroutine { yield_reg } => (
"EndCoroutine",
@@ -527,7 +527,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::Yield {
yield_reg,
@@ -539,7 +539,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::InsertAsync {
cursor,
@@ -553,7 +553,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
*key_reg as i32,
OwnedValue::Text(Rc::new("".to_string())),
*flag as u16,
format!(""),
"".to_string(),
),
Insn::InsertAwait { cursor_id } => (
"InsertAwait",
@@ -562,7 +562,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::NewRowid { reg } => (
"NewRowId",
@@ -571,7 +571,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::MustBeInt { reg } => (
"MustBeInt",
@@ -580,7 +580,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::SoftNull { reg } => (
"SoftNull",
@@ -589,7 +589,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::NotExists {
cursor,
@@ -602,7 +602,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
*rowid_reg as i32,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::OpenWriteAsync {
cursor_id,
@@ -614,7 +614,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::OpenWriteAwait {} => (
"OpenWriteAwait",
@@ -623,7 +623,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
0,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
Insn::Copy {
src_reg,
@@ -636,7 +636,7 @@ pub fn insn_to_str(program: &Program, addr: InsnReference, insn: &Insn, indent:
*amount as i32,
OwnedValue::Text(Rc::new("".to_string())),
0,
format!(""),
"".to_string(),
),
};
format!(

View File

@@ -31,7 +31,7 @@ fn main() {
match rows.next_row() {
Ok(result) => {
match result {
limbo_core::RowResult::Row(row) => {
limbo_core::RowResult::Row(_row) => {
// TODO: assert that data is correct
}
limbo_core::RowResult::IO => {