Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added

### Changed
- All usages of `unsafe` are removed, causing serialization to be slightly slower, but safe.

### Removed

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
unused_results,
variant_size_differences
)]
#![forbid(unsafe_code)]
// Enable feature(test) is enabled so that we can have benchmarks of private code
#![cfg_attr(all(test, feature = "bench_private"), feature(test))]

Expand Down Expand Up @@ -605,7 +606,7 @@
let old_max_lowest_equiv = self.lowest_equivalent(self.max());

// If total_count is at the max value, it may have saturated, so we must restat
let mut needs_restat = self.total_count == u64::max_value();

Check warning on line 609 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/lib.rs:609:52 | 609 | let mut needs_restat = self.total_count == u64::max_value(); | ^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#legacy_numeric_constants = note: `#[warn(clippy::legacy_numeric_constants)]` on by default help: use the associated constant instead | 609 - let mut needs_restat = self.total_count == u64::max_value(); 609 + let mut needs_restat = self.total_count == u64::MAX; |

for i in 0..subtrahend.distinct_values() {
let other_count = subtrahend
Expand Down Expand Up @@ -738,7 +739,7 @@
if low < 1 {
return Err(CreationError::LowIsZero);
}
if low > u64::max_value() / 2 {

Check warning on line 742 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/lib.rs:742:18 | 742 | if low > u64::max_value() / 2 { | ^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#legacy_numeric_constants help: use the associated constant instead | 742 - if low > u64::max_value() / 2 { 742 + if low > u64::MAX / 2 { |
// avoid overflow in 2 * low
return Err(CreationError::LowExceedsMax);
}
Expand Down Expand Up @@ -1042,7 +1043,7 @@
/// // etc...
/// ```
pub fn iter_quantiles(
&self,

Check warning on line 1046 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> src/lib.rs:1046:9 | 1046 | &self, | ^^^^^ the lifetime is elided here 1047 | ticks_per_half_distance: u32, 1048 | ) -> HistogramIterator<T, iterators::quantile::Iter<T>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | | | the same lifetime is hidden here | the same lifetime is hidden here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default help: use `'_` for type paths | 1048 | ) -> HistogramIterator<'_, T, iterators::quantile::Iter<'_, T>> { | +++ +++
ticks_per_half_distance: u32,
) -> HistogramIterator<T, iterators::quantile::Iter<T>> {
// TODO upper bound on ticks per half distance? 2^31 ticks is not useful
Expand Down Expand Up @@ -1104,7 +1105,7 @@
/// );
/// assert_eq!(perc.next(), None);
/// ```
pub fn iter_linear(&self, step: u64) -> HistogramIterator<T, iterators::linear::Iter<T>> {

Check warning on line 1108 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> src/lib.rs:1108:24 | 1108 | pub fn iter_linear(&self, step: u64) -> HistogramIterator<T, iterators::linear::Iter<T>> { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | | | | | the same lifetime is hidden here | | the same lifetime is hidden here | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 1108 | pub fn iter_linear(&self, step: u64) -> HistogramIterator<'_, T, iterators::linear::Iter<'_, T>> { | +++ +++
iterators::linear::Iter::new(self, step)
}

Expand Down Expand Up @@ -1142,7 +1143,7 @@
/// );
/// assert_eq!(perc.next(), None);
/// ```
pub fn iter_log(&self, start: u64, exp: f64) -> HistogramIterator<T, iterators::log::Iter<T>> {

Check warning on line 1146 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> src/lib.rs:1146:21 | 1146 | pub fn iter_log(&self, start: u64, exp: f64) -> HistogramIterator<T, iterators::log::Iter<T>> { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | | | | | the same lifetime is hidden here | | the same lifetime is hidden here | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 1146 | pub fn iter_log(&self, start: u64, exp: f64) -> HistogramIterator<'_, T, iterators::log::Iter<'_, T>> { | +++ +++
iterators::log::Iter::new(self, start, exp)
}

Expand Down Expand Up @@ -1180,7 +1181,7 @@
/// );
/// assert_eq!(perc.next(), None);
/// ```
pub fn iter_recorded(&self) -> HistogramIterator<T, iterators::recorded::Iter> {

Check warning on line 1184 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> src/lib.rs:1184:26 | 1184 | pub fn iter_recorded(&self) -> HistogramIterator<T, iterators::recorded::Iter> { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 1184 | pub fn iter_recorded(&self) -> HistogramIterator<'_, T, iterators::recorded::Iter> { | +++
iterators::recorded::Iter::new(self)
}

Expand Down Expand Up @@ -1239,7 +1240,7 @@
/// );
/// assert_eq!(perc.next(), Some(IterationValue::new(10, 1.0, 1.0, 0, 0)));
/// ```
pub fn iter_all(&self) -> HistogramIterator<T, iterators::all::Iter> {

Check warning on line 1243 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

hiding a lifetime that's elided elsewhere is confusing

warning: hiding a lifetime that's elided elsewhere is confusing --> src/lib.rs:1243:21 | 1243 | pub fn iter_all(&self) -> HistogramIterator<T, iterators::all::Iter> { | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the same lifetime is hidden here | | | the lifetime is elided here | = help: the same lifetime is referred to in inconsistent ways, making the signature confusing help: use `'_` for type paths | 1243 | pub fn iter_all(&self) -> HistogramIterator<'_, T, iterators::all::Iter> { | +++
iterators::all::Iter::new(self)
}

Expand Down Expand Up @@ -1473,8 +1474,8 @@
///
/// Note that the return value is capped at `u64::max_value()`.
pub fn highest_equivalent(&self, value: u64) -> u64 {
if value == u64::max_value() {

Check warning on line 1477 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/lib.rs:1477:21 | 1477 | if value == u64::max_value() { | ^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#legacy_numeric_constants help: use the associated constant instead | 1477 - if value == u64::max_value() { 1477 + if value == u64::MAX { |
u64::max_value()

Check warning on line 1478 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/lib.rs:1478:13 | 1478 | u64::max_value() | ^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#legacy_numeric_constants help: use the associated constant instead | 1478 - u64::max_value() 1478 + u64::MAX |
} else {
self.next_non_equivalent(value) - 1
}
Expand Down Expand Up @@ -1615,7 +1616,7 @@
// always have at least 1 bucket
let mut buckets_needed = 1;
while smallest_untrackable_value <= value {
if smallest_untrackable_value > u64::max_value() / 2 {

Check warning on line 1619 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/lib.rs:1619:45 | 1619 | if smallest_untrackable_value > u64::max_value() / 2 { | ^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#legacy_numeric_constants help: use the associated constant instead | 1619 - if smallest_untrackable_value > u64::max_value() / 2 { 1619 + if smallest_untrackable_value > u64::MAX / 2 { |
// next shift will overflow, meaning that bucket could represent values up to ones
// greater than i64::max_value, so it's the last bucket
return buckets_needed + 1;
Expand Down Expand Up @@ -1705,7 +1706,7 @@

fn reset_min(&mut self, min: u64) {
let internal_value = min & !self.unit_magnitude_mask; // Min unit-equivalent value
self.min_non_zero_value = if min == u64::max_value() {

Check warning on line 1709 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

usage of a legacy numeric method

warning: usage of a legacy numeric method --> src/lib.rs:1709:45 | 1709 | self.min_non_zero_value = if min == u64::max_value() { | ^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.96.0/index.html#legacy_numeric_constants help: use the associated constant instead | 1709 - self.min_non_zero_value = if min == u64::max_value() { 1709 + self.min_non_zero_value = if min == u64::MAX { |
min
} else {
internal_value
Expand Down
15 changes: 5 additions & 10 deletions src/serialization/v2_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ impl Serializer for V2Serializer {

debug_assert_eq!(V2_HEADER_SIZE, self.buf.len());

unsafe {
// want to treat the rest of the vec as a slice, and we've already reserved this
// space, so this way we don't have to resize() on a lot of dummy bytes.
self.buf.set_len(max_size);
}
// want to treat the rest of the vec as a slice
self.buf.resize(max_size, 0);

let counts_len = encode_counts(h, &mut self.buf[V2_HEADER_SIZE..])?;
// addition should be safe as max_size is already a usize
Expand Down Expand Up @@ -142,11 +139,11 @@ pub fn encode_counts<T: Counter>(
let mut index = 0;
let mut bytes_written = 0;

assert!(index_limit <= h.counts.len());
assert!(index_limit < h.counts.len());

while index <= index_limit {
// index is inside h.counts because of the assert above
let count = unsafe { *(h.counts.get_unchecked(index)) };
let count = h.counts[index];
index += 1;

// Non-negative values are counts for the respective value, negative values are skipping
Expand All @@ -157,9 +154,7 @@ pub fn encode_counts<T: Counter>(
zero_count = 1;

// index is inside h.counts because of the assert above
while (index <= index_limit)
&& (unsafe { *(h.counts.get_unchecked(index)) } == T::zero())
{
while (index <= index_limit) && h.counts[index] == T::zero() {
zero_count += 1;
index += 1;
}
Expand Down
Loading