Skip to content

Commit

Permalink
Use usize::BITS instead of 8 * std::mem::size_of::<usize>()
Browse files Browse the repository at this point in the history
This ports rust-lang/rust@1e2dba1e, part of rust-lang/rust#76492.
`usize::BITS` was stabilized in Rust 1.53.0.
  • Loading branch information
clint-white committed Sep 20, 2022
1 parent 52a20d8 commit 5c40e51
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ use std::slice;
// use std::vec::Drain;
use compare::Compare;
use core::fmt;
use core::mem::{size_of, swap, ManuallyDrop};
use core::mem::{swap, ManuallyDrop};
use core::ptr;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1008,11 +1008,9 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {

let tail_len = self.len() - start;

// `usize::BITS` requires Rust 1.53.0 or greater.
#[allow(clippy::manual_bits)]
#[inline(always)]
fn log2_fast(x: usize) -> usize {
8 * size_of::<usize>() - (x.leading_zeros() as usize) - 1
(usize::BITS - x.leading_zeros() - 1) as usize
}

// `rebuild` takes O(self.len()) operations
Expand Down

0 comments on commit 5c40e51

Please sign in to comment.