From 1526ab34728c7d8e61a48834033407bdf9fa10eb Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Thu, 1 Jul 2021 20:14:58 +0800 Subject: [PATCH] [all] Apply cargo fmt, and fix clippy warning of branches_sharing_code --- src/bin/thin_explore.rs | 52 ++++++++++++++-------------------- src/io_engine.rs | 6 ++-- src/pack/node_encode.rs | 9 ++---- src/pdata/btree_leaf_walker.rs | 3 +- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/src/bin/thin_explore.rs b/src/bin/thin_explore.rs index 193181b..26776ab 100644 --- a/src/bin/thin_explore.rs +++ b/src/bin/thin_explore.rs @@ -183,24 +183,19 @@ impl<'a> StatefulWidget for SBWidget<'a> { format!("{}k", sb.data_block_size * 2), ]; - let table = Table::new( - vec![ - Row::new(flags), - Row::new(block), - Row::new(uuid), - Row::new(version), - Row::new(time), - Row::new(transaction_id), - Row::new(metadata_snap), - Row::new(mapping_root), - Row::new(details_root), - Row::new(data_block_size), - ] - ) - .header( - Row::new(vec!["Field", "Value"]) - .style(Style::default().fg(Color::Yellow)) - ) + let table = Table::new(vec![ + Row::new(flags), + Row::new(block), + Row::new(uuid), + Row::new(version), + Row::new(time), + Row::new(transaction_id), + Row::new(metadata_snap), + Row::new(mapping_root), + Row::new(details_root), + Row::new(data_block_size), + ]) + .header(Row::new(vec!["Field", "Value"]).style(Style::default().fg(Color::Yellow))) .block( Block::default() .borders(Borders::ALL) @@ -251,19 +246,14 @@ impl<'a> Widget for HeaderWidget<'a> { let max_entries = vec!["max_entries".to_string(), format!("{}", hdr.max_entries)]; let value_size = vec!["value size".to_string(), format!("{}", hdr.value_size)]; - let table = Table::new( - vec![ - Row::new(block), - Row::new(kind), - Row::new(nr_entries), - Row::new(max_entries), - Row::new(value_size), - ] - ) - .header( - Row::new(vec!["Field", "Value"]) - .style(Style::default().fg(Color::Yellow)) - ) + let table = Table::new(vec![ + Row::new(block), + Row::new(kind), + Row::new(nr_entries), + Row::new(max_entries), + Row::new(value_size), + ]) + .header(Row::new(vec!["Field", "Value"]).style(Style::default().fg(Color::Yellow))) .block(Block::default().borders(Borders::ALL).title(self.title)) .widths(&[Constraint::Length(20), Constraint::Length(60)]) .style(Style::default().fg(Color::White)) diff --git a/src/io_engine.rs b/src/io_engine.rs index e38f995..2bd7687 100644 --- a/src/io_engine.rs +++ b/src/io_engine.rs @@ -258,8 +258,7 @@ impl AsyncIoEngine { let fd_inner = inner.input.as_raw_fd(); for (i, b) in blocks.iter().enumerate() { - let read_e = opcode::Read::new( - types::Fd(fd_inner), b.data, BLOCK_SIZE as u32) + let read_e = opcode::Read::new(types::Fd(fd_inner), b.data, BLOCK_SIZE as u32) .offset(b.loc as i64 * BLOCK_SIZE as i64); unsafe { @@ -310,8 +309,7 @@ impl AsyncIoEngine { let fd_inner = inner.input.as_raw_fd(); for (i, b) in blocks.iter().enumerate() { - let write_e = opcode::Write::new( - types::Fd(fd_inner), b.data, BLOCK_SIZE as u32) + let write_e = opcode::Write::new(types::Fd(fd_inner), b.data, BLOCK_SIZE as u32) .offset(b.loc as i64 * BLOCK_SIZE as i64); unsafe { diff --git a/src/pack/node_encode.rs b/src/pack/node_encode.rs index d146ca3..76af735 100644 --- a/src/pack/node_encode.rs +++ b/src/pack/node_encode.rs @@ -59,11 +59,11 @@ fn summarise_node(data: &[u8]) -> IResult<&[u8], NodeSummary> { pub fn pack_btree_node(w: &mut W, data: &[u8]) -> PResult<()> { let (_, info) = nom_to_pr(summarise_node(data))?; + let (i, hdr) = nom_to_pr(take(32usize)(data))?; + let (i, keys) = nom_to_pr(run64(i, info.max_entries))?; if info.is_leaf { if info.value_size == std::mem::size_of::() { - let (i, hdr) = nom_to_pr(take(32usize)(data))?; - let (i, keys) = nom_to_pr(run64(i, info.max_entries))?; let (tail, values) = nom_to_pr(run64(i, info.max_entries))?; io_to_pr(pack_literal(w, hdr))?; @@ -76,8 +76,7 @@ pub fn pack_btree_node(w: &mut W, data: &[u8]) -> PResult<()> { Ok(()) } else { // We don't bother packing the values if they aren't u64 - let (i, hdr) = nom_to_pr(take(32usize)(data))?; - let (tail, keys) = nom_to_pr(run64(i, info.max_entries))?; + let tail = i; io_to_pr(pack_literal(w, hdr))?; io_to_pr(pack_u64s(w, &keys))?; @@ -87,8 +86,6 @@ pub fn pack_btree_node(w: &mut W, data: &[u8]) -> PResult<()> { } } else { // Internal node, values are also u64s - let (i, hdr) = nom_to_pr(take(32usize)(data))?; - let (i, keys) = nom_to_pr(run64(i, info.max_entries))?; let (tail, values) = nom_to_pr(run64(i, info.max_entries))?; io_to_pr(pack_literal(w, hdr))?; diff --git a/src/pdata/btree_leaf_walker.rs b/src/pdata/btree_leaf_walker.rs index fdccdcd..b19da99 100644 --- a/src/pdata/btree_leaf_walker.rs +++ b/src/pdata/btree_leaf_walker.rs @@ -210,14 +210,13 @@ impl<'a> LeafWalker<'a> { let depth = self.get_depth::(path, root, true)?; + self.sm_inc(root); if depth == 0 { // root is a leaf - self.sm_inc(root); self.leaves.insert(root as usize); visitor.visit(&kr, root)?; Ok(()) } else { - self.sm_inc(root); let root = self.engine.read(root).map_err(|_| io_err(path))?; self.walk_node(depth - 1, path, visitor, &kr, &root, true)