diff --git a/Cargo.toml b/Cargo.toml index 9b1753a..84eb973 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "wellen" -version = "0.9.6" +version = "0.9.7" edition = "2021" authors = ["Kevin Laeufer "] description = "Fast VCD and FST library for waveform viewers written in Rust." diff --git a/benches/wavemem.rs b/benches/wavemem.rs index 57420d0..fcae948 100644 --- a/benches/wavemem.rs +++ b/benches/wavemem.rs @@ -2,7 +2,7 @@ // released under BSD 3-Clause License // author: Kevin Laeufer -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) { diff --git a/src/fst.rs b/src/fst.rs index de7e9af..be5abaf 100644 --- a/src/fst.rs +++ b/src/fst.rs @@ -111,7 +111,7 @@ impl SignalSourceImplementation for FstWaveDatabase { .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(); @@ -122,7 +122,7 @@ impl SignalSourceImplementation for FstWaveDatabase { 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) { @@ -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, entries: usize, bits: u32) -> Vec { +fn expand_entries(from: States, to: States, old: &[u8], entries: usize, bits: u32) -> Vec { 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); diff --git a/src/ghw/common.rs b/src/ghw/common.rs index 6fcb632..69c60f6 100644 --- a/src/ghw/common.rs +++ b/src/ghw/common.rs @@ -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!( diff --git a/src/ghw/hierarchy.rs b/src/ghw/hierarchy.rs index cb79f73..36f99f0 100644 --- a/src/ghw/hierarchy.rs +++ b/src/ghw/hierarchy.rs @@ -35,7 +35,7 @@ pub(crate) fn read_ghw_header(input: &mut impl BufRead) -> Result { // 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), @@ -1097,6 +1097,7 @@ impl GhwSignalTracker { } } +#[allow(clippy::too_many_arguments)] fn add_var( tables: &GhwTables, input: &mut impl BufRead, diff --git a/src/hierarchy.rs b/src/hierarchy.rs index bc04803..1e0b3d2 100644 --- a/src/hierarchy.rs +++ b/src/hierarchy.rs @@ -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) => { @@ -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 { @@ -1050,6 +1050,7 @@ impl HierarchyBuilder { } } + #[allow(clippy::too_many_arguments)] pub fn add_var( &mut self, name: HierarchyStringId, diff --git a/src/vcd.rs b/src/vcd.rs index 75ea7e1..9b6381d 100644 --- a/src/vcd.rs +++ b/src/vcd.rs @@ -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::()?; let var_type = FstVhdlVarType::try_from_primitive((arg >> FST_SUP_VAR_DATA_TYPE_BITS) as u8)?; let data_type = @@ -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::()?; let string_ref = h.add_string(path); path_names.insert(id, string_ref); Ok(None) @@ -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::()?; + let line = std::str::from_utf8(tokens[3])?.parse::()?; let is_instance = false; Ok(Some(Attribute::SourceLoc( path_names[&path_id], @@ -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) = @@ -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::() { Ok(len) => len, Err(_) => { return Err(VcdParseError::VcdVarLengthParsing( @@ -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::()?; let value = Timescale::new(factor_int, convert_timescale_unit(unit)); h.set_timescale(value); Ok(()) @@ -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 }; @@ -396,16 +396,16 @@ fn parse_inner_index(index: &[u8]) -> Option { 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::().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::().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::().unwrap(); Some(VarIndex::new(msb, lsb)) } } @@ -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, @@ -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::().unwrap(); encoder.time_change(int_value); } BodyCmd::Value(value, id) => { @@ -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 diff --git a/src/viewers.rs b/src/viewers.rs index 71a6118..ff1004d 100644 --- a/src/viewers.rs +++ b/src/viewers.rs @@ -33,7 +33,6 @@ pub struct HeaderResult { pub body: ReadBodyContinuation, } -/// pub fn read_header(filename: &str, options: &LoadOptions) -> Result { let file_format = open_and_detect_file_format(filename); match file_format { diff --git a/src/wavemem.rs b/src/wavemem.rs index 70e3b21..652b9f0 100644 --- a/src/wavemem.rs +++ b/src/wavemem.rs @@ -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; @@ -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); @@ -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 { @@ -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 diff --git a/tests/diff_tests.rs b/tests/diff_tests.rs index 052b3bd..9e094fe 100644 --- a/tests/diff_tests.rs +++ b/tests/diff_tests.rs @@ -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()), }