Skip to content

Commit

Permalink
fix all remaining clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed May 7, 2024
1 parent b305227 commit d3ee419
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[package]
name = "wellen"
version = "0.9.6"
version = "0.9.7"
edition = "2021"
authors = ["Kevin Laeufer <[email protected]>"]
description = "Fast VCD and FST library for waveform viewers written in Rust."
Expand Down
2 changes: 1 addition & 1 deletion benches/wavemem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// released under BSD 3-Clause License
// author: Kevin Laeufer <[email protected]>

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};
use wellen::check_states_pub;

fn criterion_benchmark(c: &mut Criterion) {
Expand Down
8 changes: 4 additions & 4 deletions src/fst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<R: BufRead + Seek> SignalSourceImplementation for FstWaveDatabase<R> {
.enumerate()
.map(|(pos, idx)| (idx, pos)),
);
let foo = |time: u64, handle: FstSignalHandle, value: FstSignalValue| {
let callback = |time: u64, handle: FstSignalHandle, value: FstSignalValue| {
// determine time index
while *(index_and_time.1) < time {
index_and_time = time_table.next().unwrap();
Expand All @@ -122,7 +122,7 @@ impl<R: BufRead + Seek> SignalSourceImplementation for FstWaveDatabase<R> {
signals[signal_pos].add_change(time_idx, handle, value);
};

self.reader.read_signals(&filter, foo).unwrap();
self.reader.read_signals(&filter, callback).unwrap();
signals.into_iter().map(|w| w.finish()).collect()
}
fn print_statistics(&self) {
Expand Down Expand Up @@ -308,13 +308,13 @@ pub(crate) fn get_bytes_per_entry(len: usize, has_meta: bool) -> usize {

const META_MASK: u8 = 3 << 6;

fn expand_entries(from: States, to: States, old: &Vec<u8>, entries: usize, bits: u32) -> Vec<u8> {
fn expand_entries(from: States, to: States, old: &[u8], entries: usize, bits: u32) -> Vec<u8> {
let (from_len, from_meta) = get_len_and_meta(from, bits);
let from_bytes_per_entry = get_bytes_per_entry(from_len, from_meta);
let (to_len, to_meta) = get_len_and_meta(to, bits);

if from_len == to_len && from_meta == to_meta {
return old.clone(); // no change necessary
return Vec::from(old); // no change necessary
}

let to_bytes_per_entry = get_bytes_per_entry(to_len, to_meta);
Expand Down
2 changes: 1 addition & 1 deletion src/ghw/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn check_magic_end(
) -> Result<()> {
let mut end_magic = [0u8; 4];
input.read_exact(&mut end_magic)?;
if &end_magic == expected {
if end_magic == expected {
Ok(())
} else {
Err(GhwParseError::UnexpectedSection(format!(
Expand Down
3 changes: 2 additions & 1 deletion src/ghw/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(crate) fn read_ghw_header(input: &mut impl BufRead) -> Result<HeaderData> {
// check full header
let mut magic_rest = [0u8; GHW_HEADER_START.len() - 2];
input.read_exact(&mut magic_rest)?;
if &magic_rest != &GHW_HEADER_START[2..] {
if magic_rest != GHW_HEADER_START[2..] {
return Err(GhwParseError::UnexpectedHeaderMagic(format!(
"{}{}",
String::from_utf8_lossy(&comp_header),
Expand Down Expand Up @@ -1097,6 +1097,7 @@ impl GhwSignalTracker {
}
}

#[allow(clippy::too_many_arguments)]
fn add_var(
tables: &GhwTables,
input: &mut impl BufRead,
Expand Down
5 changes: 3 additions & 2 deletions src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl Var {
}

/// Full hierarchical name of the variable.
pub fn full_name<'a>(&self, hierarchy: &Hierarchy) -> String {
pub fn full_name(&self, hierarchy: &Hierarchy) -> String {
match self.parent {
None => self.name(hierarchy).to_string(),
Some(parent) => {
Expand Down Expand Up @@ -403,7 +403,7 @@ impl Scope {
}

/// Full hierarchical name of the scope.
pub fn full_name<'a>(&self, hierarchy: &Hierarchy) -> String {
pub fn full_name(&self, hierarchy: &Hierarchy) -> String {
let mut parents = Vec::new();
let mut parent = self.parent;
while let Some(id) = parent {
Expand Down Expand Up @@ -1050,6 +1050,7 @@ impl HierarchyBuilder {
}
}

#[allow(clippy::too_many_arguments)]
pub fn add_var(
&mut self,
name: HierarchyStringId,
Expand Down
34 changes: 15 additions & 19 deletions src/vcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn parse_attribute(
return Err(unexpected_n_tokens("attribute", &tokens));
}
let type_name = std::str::from_utf8(tokens[2])?.to_string();
let arg = u64::from_str_radix(std::str::from_utf8(tokens[3])?, 10)?;
let arg = std::str::from_utf8(tokens[3])?.parse::<u64>()?;
let var_type =
FstVhdlVarType::try_from_primitive((arg >> FST_SUP_VAR_DATA_TYPE_BITS) as u8)?;
let data_type =
Expand All @@ -150,7 +150,7 @@ fn parse_attribute(
return Err(unexpected_n_tokens("attribute", &tokens));
}
let path = std::str::from_utf8(tokens[2])?.to_string();
let id = u64::from_str_radix(std::str::from_utf8(tokens[3])?, 10)?;
let id = std::str::from_utf8(tokens[3])?.parse::<u64>()?;
let string_ref = h.add_string(path);
path_names.insert(id, string_ref);
Ok(None)
Expand All @@ -162,8 +162,8 @@ fn parse_attribute(
// instance of the normal source path
return Err(unexpected_n_tokens("attribute", &tokens));
}
let path_id = u64::from_str_radix(std::str::from_utf8(tokens[2])?, 10)?;
let line = u64::from_str_radix(std::str::from_utf8(tokens[3])?, 10)?;
let path_id = std::str::from_utf8(tokens[2])?.parse::<u64>()?;
let line = std::str::from_utf8(tokens[3])?.parse::<u64>()?;
let is_instance = false;
Ok(Some(Attribute::SourceLoc(
path_names[&path_id],
Expand Down Expand Up @@ -220,7 +220,7 @@ fn read_hierarchy(
}
};

let foo = |cmd: HeaderCmd| match cmd {
let callback = |cmd: HeaderCmd| match cmd {
HeaderCmd::Scope(tpe, name) => {
let flatten = options.remove_scopes_with_empty_name && name.is_empty();
let (declaration_source, instance_source) =
Expand All @@ -241,7 +241,7 @@ fn read_hierarchy(
Ok(())
}
HeaderCmd::Var(tpe, size, id, name) => {
let length = match u32::from_str_radix(std::str::from_utf8(size).unwrap(), 10) {
let length = match std::str::from_utf8(size).unwrap().parse::<u32>() {
Ok(len) => len,
Err(_) => {
return Err(VcdParseError::VcdVarLengthParsing(
Expand Down Expand Up @@ -284,7 +284,7 @@ fn read_hierarchy(
Ok(())
}
HeaderCmd::Timescale(factor, unit) => {
let factor_int = u32::from_str_radix(std::str::from_utf8(factor).unwrap(), 10)?;
let factor_int = std::str::from_utf8(factor)?.parse::<u32>()?;
let value = Timescale::new(factor_int, convert_timescale_unit(unit));
h.set_timescale(value);
Ok(())
Expand All @@ -297,7 +297,7 @@ fn read_hierarchy(
}
};

read_vcd_header(input, foo)?;
read_vcd_header(input, callback)?;
let end = input.stream_position().unwrap();
let hierarchy = h.finish();
let lookup = if use_id_map { Some(id_map) } else { None };
Expand Down Expand Up @@ -396,16 +396,16 @@ fn parse_inner_index(index: &[u8]) -> Option<VarIndex> {
match sep {
None => {
let inner_str = std::str::from_utf8(index).unwrap();
let bit = i32::from_str_radix(inner_str, 10).unwrap();
let bit = inner_str.parse::<i32>().unwrap();
Some(VarIndex::new(bit, bit))
}
Some(pos) => {
let msb_bytes = &index[0..pos];
let msb_str = std::str::from_utf8(msb_bytes).unwrap();
let msb = i32::from_str_radix(msb_str, 10).unwrap();
let msb = msb_str.parse::<i32>().unwrap();
let lsb_bytes = &index[(pos + 1)..index.len()];
let lsb_str = std::str::from_utf8(lsb_bytes).unwrap();
let lsb = i32::from_str_radix(lsb_str, 10).unwrap();
let lsb = lsb_str.parse::<i32>().unwrap();
Some(VarIndex::new(msb, lsb))
}
}
Expand Down Expand Up @@ -911,7 +911,7 @@ fn read_values(
}
}

fn read_single_stream_of_values<'a>(
fn read_single_stream_of_values(
input: &[u8],
stop_pos: usize,
is_first: bool,
Expand Down Expand Up @@ -956,8 +956,7 @@ fn read_single_stream_of_values<'a>(
match cmd {
BodyCmd::Time(value) => {
found_first_time_step = true;
let int_value =
u64::from_str_radix(std::str::from_utf8(value).unwrap(), 10).unwrap();
let int_value = std::str::from_utf8(value).unwrap().parse::<u64>().unwrap();
encoder.time_change(int_value);
}
BodyCmd::Value(value, id) => {
Expand Down Expand Up @@ -991,11 +990,8 @@ fn read_single_stream_of_values<'a>(
#[inline]
fn advance_to_first_newline(input: &[u8]) -> (&[u8], usize) {
for (pos, byte) in input.iter().enumerate() {
match *byte {
b'\n' => {
return (&input[pos..], pos);
}
_ => {}
if *byte == b'\n' {
return (&input[pos..], pos);
}
}
(&[], 0) // no whitespaces found
Expand Down
1 change: 0 additions & 1 deletion src/viewers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct HeaderResult {
pub body: ReadBodyContinuation,
}

///
pub fn read_header(filename: &str, options: &LoadOptions) -> Result<HeaderResult> {
let file_format = open_and_detect_file_format(filename);
match file_format {
Expand Down
29 changes: 18 additions & 11 deletions src/wavemem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use bytesize::ByteSize;
use num_enum::TryFromPrimitive;
use rayon::prelude::*;
use std::borrow::Cow;
use std::cmp::Ordering;
use std::io::Read;
use std::num::NonZeroU32;

Expand Down Expand Up @@ -234,7 +235,7 @@ fn load_reals(
let changed = if out.is_empty() {
true
} else {
&out[out.len() - 8..] != buf
out[out.len() - 8..] != buf
};
if changed {
out.append(&mut buf);
Expand Down Expand Up @@ -326,7 +327,7 @@ pub(crate) fn check_if_changed_and_truncate(bytes_per_entry: usize, out: &mut Ve
} else {
let prev_start = out.len() - 2 * bytes_per_entry;
let new_start = out.len() - bytes_per_entry;
&out[prev_start..new_start] != &out[new_start..]
out[prev_start..new_start] != out[new_start..]
};

if !changed {
Expand Down Expand Up @@ -465,15 +466,21 @@ impl Encoder {
pub fn time_change(&mut self, time: u64) {
// sanity check to make sure that time is increasing
if let Some(prev_time) = self.time_table.last() {
if *prev_time == time {
return; // ignore calls to time_change that do not actually change anything
} else if *prev_time > time {
println!(
"WARN: time decreased from {} to {}. Skipping!",
*prev_time, time
);
self.skipping_time_step = true;
return;
match prev_time.cmp(&time) {
Ordering::Equal => {
return; // ignore calls to time_change that do not actually change anything
}
Ordering::Greater => {
println!(
"WARN: time decreased from {} to {}. Skipping!",
*prev_time, time
);
self.skipping_time_step = true;
return;
}
Ordering::Less => {
// this is the normal situation where we actually increment the time
}
}
}
// if we run out of time indices => start a new block
Expand Down
18 changes: 10 additions & 8 deletions tests/diff_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ fn diff_hierarchy(

fn diff_meta(ours: &Hierarchy, ref_header: &::vcd::Header) {
match &ref_header.version {
None => match ours.file_format() {
FileFormat::Vcd => assert!(ours.version().is_empty(), "{}", ours.version()),
_ => {}
},
None => {
if ours.file_format() == FileFormat::Vcd {
assert!(ours.version().is_empty(), "{}", ours.version());
}
}
Some(version) => assert_eq!(version, ours.version()),
}

match &ref_header.date {
None => match ours.file_format() {
FileFormat::Vcd => assert!(ours.date().is_empty(), "{}", ours.date()),
_ => {}
},
None => {
if ours.file_format() == FileFormat::Vcd {
assert!(ours.date().is_empty(), "{}", ours.date());
}
}
Some(date) => assert_eq!(date, ours.date()),
}

Expand Down

0 comments on commit d3ee419

Please sign in to comment.