Skip to content

Commit

Permalink
fix some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Oct 4, 2024
1 parent 3862a4a commit 32ce555
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
7 changes: 4 additions & 3 deletions wellen/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub enum VarType {
}

/// Signal directions of a variable. Currently these have the exact same meaning as in the FST format.
///
/// For VCD inputs, all variables will be marked as `VarDirection::Unknown` since no direction information is included.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -486,7 +487,7 @@ impl<'a> HierarchyItemIdIterator<'a> {
}
}

impl<'a> Iterator for HierarchyItemIdIterator<'a> {
impl Iterator for HierarchyItemIdIterator<'_> {
type Item = HierarchyItemId;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -531,7 +532,7 @@ pub struct HierarchyVarRefIterator<'a> {
underlying: HierarchyItemIdIterator<'a>,
}

impl<'a> Iterator for HierarchyVarRefIterator<'a> {
impl Iterator for HierarchyVarRefIterator<'_> {
type Item = VarRef;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -549,7 +550,7 @@ pub struct HierarchyScopeRefIterator<'a> {
underlying: HierarchyItemIdIterator<'a>,
}

impl<'a> Iterator for HierarchyScopeRefIterator<'a> {
impl Iterator for HierarchyScopeRefIterator<'_> {
type Item = ScopeRef;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
12 changes: 5 additions & 7 deletions wellen/src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use crate::fst::{get_bytes_per_entry, get_len_and_meta, push_zeros};
use crate::hierarchy::SignalRef;
use crate::vcd::usize_div_ceil;
use crate::wavemem::{check_if_changed_and_truncate, States};
use crate::{Hierarchy, SignalEncoding};
use num_enum::TryFromPrimitive;
Expand All @@ -25,7 +24,7 @@ pub enum SignalValue<'a> {
Real(Real),
}

impl<'a> Display for SignalValue<'a> {
impl Display for SignalValue<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match &self {
SignalValue::Binary(data, bits) => {
Expand All @@ -43,7 +42,7 @@ impl<'a> Display for SignalValue<'a> {
}
}

impl<'a> SignalValue<'a> {
impl SignalValue<'_> {
pub fn to_bit_string(&self) -> Option<String> {
match &self {
SignalValue::Binary(data, bits) => Some(two_state_to_bit_string(data, *bits)),
Expand Down Expand Up @@ -319,7 +318,7 @@ impl BitVectorBuilder {
let meta_data = (local_encoding as u8) << 6;
self.data.push(value | meta_data);
} else {
let num_bytes = usize_div_ceil(self.bits as usize, local_encoding.bits_in_a_byte());
let num_bytes = (self.bits as usize).div_ceil(local_encoding.bits_in_a_byte());
let data = value.data().unwrap();
assert_eq!(data.len(), num_bytes);
let (local_len, local_has_meta) = get_len_and_meta(local_encoding, self.bits);
Expand Down Expand Up @@ -700,7 +699,6 @@ impl SignalSource {
#[cfg(test)]
mod tests {
use super::*;
use crate::vcd::usize_div_ceil;

#[test]
fn test_sizes() {
Expand Down Expand Up @@ -728,7 +726,7 @@ mod tests {

for bits in 0..(full_str_len + 1) {
let expected: String = full_str.chars().skip(full_str_len - bits).collect();
let number_of_bytes = usize_div_ceil(bits, 8);
let number_of_bytes = bits.div_ceil(8);
let drop_bytes = data0.len() - number_of_bytes;
let data = &data0[drop_bytes..];
assert_eq!(
Expand All @@ -750,7 +748,7 @@ mod tests {

for bits in 0..(full_str_len + 1) {
let expected: String = full_str.chars().skip(full_str_len - bits).collect();
let number_of_bytes = usize_div_ceil(bits, 4);
let number_of_bytes = bits.div_ceil(4);
let drop_bytes = data0.len() - number_of_bytes;
let data = &data0[drop_bytes..];
assert_eq!(
Expand Down
23 changes: 6 additions & 17 deletions wellen/src/vcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,25 +910,15 @@ enum HeaderCmd<'a> {
/// The minimum number of bytes we want to read per thread.
const MIN_CHUNK_SIZE: usize = 8 * 1024;

#[inline]
pub fn usize_div_ceil(a: usize, b: usize) -> usize {
(a + b - 1) / b
}

#[inline]
pub fn u32_div_ceil(a: u32, b: u32) -> u32 {
(a + b - 1) / b
}

/// Returns starting byte and read length for every thread. Note that read-length is just an
/// approximation and the thread might have to read beyond or might also run out of data before
/// reaching read length.
#[inline]
fn determine_thread_chunks(body_len: usize) -> Vec<(usize, usize)> {
let max_threads = rayon::current_num_threads();
let number_of_threads_for_min_chunk_size = usize_div_ceil(body_len, MIN_CHUNK_SIZE);
let number_of_threads_for_min_chunk_size = body_len.div_ceil(MIN_CHUNK_SIZE);
let num_threads = std::cmp::min(max_threads, number_of_threads_for_min_chunk_size);
let chunk_size = usize_div_ceil(body_len, num_threads);
let chunk_size = body_len.div_ceil(num_threads);
// TODO: for large file it might make sense to have more chunks than threads
(0..num_threads)
.map(|ii| (ii * chunk_size, chunk_size))
Expand Down Expand Up @@ -1221,16 +1211,15 @@ impl<'a> Iterator for BodyReader<'a> {
}
}
}
_ => match token_start {
None => {
_ => {
if token_start.is_none() {
token_start = Some(pos);
if prev_token.is_none() {
// remember the start of the first token
start_pos = pos;
}
}
Some(_) => {}
},
}
}
}
// update final position
Expand All @@ -1257,7 +1246,7 @@ enum BodyCmd<'a> {
Value(&'a [u8], &'a [u8]),
}

impl<'a> Debug for BodyCmd<'a> {
impl Debug for BodyCmd<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
BodyCmd::Time(value) => {
Expand Down
11 changes: 5 additions & 6 deletions wellen/src/wavemem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::hierarchy::{Hierarchy, SignalRef};
use crate::signals::{
FixedWidthEncoding, Real, Signal, SignalSource, SignalSourceImplementation, Time, TimeTableIdx,
};
use crate::vcd::{u32_div_ceil, usize_div_ceil};
use crate::{SignalEncoding, TimeTable};
use bytesize::ByteSize;
use num_enum::TryFromPrimitive;
Expand Down Expand Up @@ -278,7 +277,7 @@ fn load_fixed_len_signal(
// the lower 2 bits of the time idx delta encode how many state bits are encoded in the local signal
let local_encoding =
States::try_from_primitive((time_idx_delta_raw & 0x3) as u8).unwrap();
let num_bytes = usize_div_ceil(other_len as usize, local_encoding.bits_in_a_byte());
let num_bytes = (other_len as usize).div_ceil(local_encoding.bits_in_a_byte());
let mut buf = vec![0u8; num_bytes];
data.read_exact(buf.as_mut()).unwrap();
let (local_len, local_has_meta) = get_len_and_meta(local_encoding, bits);
Expand Down Expand Up @@ -635,9 +634,9 @@ impl SignalEncodingMetaData {

fn compressed(max_states: States, uncompressed_len: usize) -> Self {
// turn the length into a value that we can actually encode
let uncompressed_len_approx =
u32_div_ceil(uncompressed_len as u32, SIGNAL_DECOMPRESSED_LEN_DIV)
* SIGNAL_DECOMPRESSED_LEN_DIV;
let uncompressed_len_approx = (uncompressed_len as u32)
.div_ceil(SIGNAL_DECOMPRESSED_LEN_DIV)
* SIGNAL_DECOMPRESSED_LEN_DIV;
SignalEncodingMetaData {
compression: SignalCompression::Compressed(uncompressed_len_approx as usize),
max_states,
Expand All @@ -663,7 +662,7 @@ impl SignalEncodingMetaData {
match &self.compression {
SignalCompression::Compressed(decompressed_len) => {
let decompressed_len_bits =
u32_div_ceil((*decompressed_len) as u32, SIGNAL_DECOMPRESSED_LEN_DIV);
((*decompressed_len) as u32).div_ceil(SIGNAL_DECOMPRESSED_LEN_DIV);

((decompressed_len_bits as u64) << 3) | (1 << 2) | (self.max_states as u64)
}
Expand Down
2 changes: 1 addition & 1 deletion wellen/tests/fst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn test_nvc_vhdl_test_bool_issue_16() {
.get_signal(var.signal_ref())
.unwrap()
.iter_changes()
.map(|(time, value)| format!("{time} {}", value.to_string()))
.map(|(time, value)| format!("{time} {}", value))
.collect::<Vec<_>>();
assert_eq!(
time_and_values,
Expand Down

0 comments on commit 32ce555

Please sign in to comment.