[all] Apply cargo fmt, and fix clippy warning of branches_sharing_code

This commit is contained in:
Ming-Hung Tsai 2021-07-01 20:14:58 +08:00
parent 5ac9ae2dae
commit 1526ab3472
4 changed files with 27 additions and 43 deletions

View File

@ -183,8 +183,7 @@ impl<'a> StatefulWidget for SBWidget<'a> {
format!("{}k", sb.data_block_size * 2), format!("{}k", sb.data_block_size * 2),
]; ];
let table = Table::new( let table = Table::new(vec![
vec![
Row::new(flags), Row::new(flags),
Row::new(block), Row::new(block),
Row::new(uuid), Row::new(uuid),
@ -195,12 +194,8 @@ impl<'a> StatefulWidget for SBWidget<'a> {
Row::new(mapping_root), Row::new(mapping_root),
Row::new(details_root), Row::new(details_root),
Row::new(data_block_size), Row::new(data_block_size),
] ])
) .header(Row::new(vec!["Field", "Value"]).style(Style::default().fg(Color::Yellow)))
.header(
Row::new(vec!["Field", "Value"])
.style(Style::default().fg(Color::Yellow))
)
.block( .block(
Block::default() Block::default()
.borders(Borders::ALL) .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 max_entries = vec!["max_entries".to_string(), format!("{}", hdr.max_entries)];
let value_size = vec!["value size".to_string(), format!("{}", hdr.value_size)]; let value_size = vec!["value size".to_string(), format!("{}", hdr.value_size)];
let table = Table::new( let table = Table::new(vec![
vec![
Row::new(block), Row::new(block),
Row::new(kind), Row::new(kind),
Row::new(nr_entries), Row::new(nr_entries),
Row::new(max_entries), Row::new(max_entries),
Row::new(value_size), Row::new(value_size),
] ])
) .header(Row::new(vec!["Field", "Value"]).style(Style::default().fg(Color::Yellow)))
.header(
Row::new(vec!["Field", "Value"])
.style(Style::default().fg(Color::Yellow))
)
.block(Block::default().borders(Borders::ALL).title(self.title)) .block(Block::default().borders(Borders::ALL).title(self.title))
.widths(&[Constraint::Length(20), Constraint::Length(60)]) .widths(&[Constraint::Length(20), Constraint::Length(60)])
.style(Style::default().fg(Color::White)) .style(Style::default().fg(Color::White))

View File

@ -258,8 +258,7 @@ impl AsyncIoEngine {
let fd_inner = inner.input.as_raw_fd(); let fd_inner = inner.input.as_raw_fd();
for (i, b) in blocks.iter().enumerate() { for (i, b) in blocks.iter().enumerate() {
let read_e = opcode::Read::new( let read_e = opcode::Read::new(types::Fd(fd_inner), b.data, BLOCK_SIZE as u32)
types::Fd(fd_inner), b.data, BLOCK_SIZE as u32)
.offset(b.loc as i64 * BLOCK_SIZE as i64); .offset(b.loc as i64 * BLOCK_SIZE as i64);
unsafe { unsafe {
@ -310,8 +309,7 @@ impl AsyncIoEngine {
let fd_inner = inner.input.as_raw_fd(); let fd_inner = inner.input.as_raw_fd();
for (i, b) in blocks.iter().enumerate() { for (i, b) in blocks.iter().enumerate() {
let write_e = opcode::Write::new( let write_e = opcode::Write::new(types::Fd(fd_inner), b.data, BLOCK_SIZE as u32)
types::Fd(fd_inner), b.data, BLOCK_SIZE as u32)
.offset(b.loc as i64 * BLOCK_SIZE as i64); .offset(b.loc as i64 * BLOCK_SIZE as i64);
unsafe { unsafe {

View File

@ -59,11 +59,11 @@ fn summarise_node(data: &[u8]) -> IResult<&[u8], NodeSummary> {
pub fn pack_btree_node<W: Write>(w: &mut W, data: &[u8]) -> PResult<()> { pub fn pack_btree_node<W: Write>(w: &mut W, data: &[u8]) -> PResult<()> {
let (_, info) = nom_to_pr(summarise_node(data))?; 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.is_leaf {
if info.value_size == std::mem::size_of::<u64>() { if info.value_size == std::mem::size_of::<u64>() {
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))?; let (tail, values) = nom_to_pr(run64(i, info.max_entries))?;
io_to_pr(pack_literal(w, hdr))?; io_to_pr(pack_literal(w, hdr))?;
@ -76,8 +76,7 @@ pub fn pack_btree_node<W: Write>(w: &mut W, data: &[u8]) -> PResult<()> {
Ok(()) Ok(())
} else { } else {
// We don't bother packing the values if they aren't u64 // We don't bother packing the values if they aren't u64
let (i, hdr) = nom_to_pr(take(32usize)(data))?; let tail = i;
let (tail, keys) = nom_to_pr(run64(i, info.max_entries))?;
io_to_pr(pack_literal(w, hdr))?; io_to_pr(pack_literal(w, hdr))?;
io_to_pr(pack_u64s(w, &keys))?; io_to_pr(pack_u64s(w, &keys))?;
@ -87,8 +86,6 @@ pub fn pack_btree_node<W: Write>(w: &mut W, data: &[u8]) -> PResult<()> {
} }
} else { } else {
// Internal node, values are also u64s // 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))?; let (tail, values) = nom_to_pr(run64(i, info.max_entries))?;
io_to_pr(pack_literal(w, hdr))?; io_to_pr(pack_literal(w, hdr))?;

View File

@ -210,14 +210,13 @@ impl<'a> LeafWalker<'a> {
let depth = self.get_depth::<V>(path, root, true)?; let depth = self.get_depth::<V>(path, root, true)?;
self.sm_inc(root);
if depth == 0 { if depth == 0 {
// root is a leaf // root is a leaf
self.sm_inc(root);
self.leaves.insert(root as usize); self.leaves.insert(root as usize);
visitor.visit(&kr, root)?; visitor.visit(&kr, root)?;
Ok(()) Ok(())
} else { } else {
self.sm_inc(root);
let root = self.engine.read(root).map_err(|_| io_err(path))?; let root = self.engine.read(root).map_err(|_| io_err(path))?;
self.walk_node(depth - 1, path, visitor, &kr, &root, true) self.walk_node(depth - 1, path, visitor, &kr, &root, true)