From ee76be54861189275be483c3f4a72531dc7f7698 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 28 Mar 2015 16:07:25 +0300 Subject: Remove unnecessary `as usize` --- src/libcollections/bit.rs | 34 +++++++++++++++++----------------- src/libcollections/enum_set.rs | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/libcollections') diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index fcf8c815694..99577b0d7e7 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -191,17 +191,17 @@ fn blocks_for_bits(bits: usize) -> usize { // // Note that we can technically avoid this branch with the expression // `(nbits + u32::BITS - 1) / 32::BITS`, but if nbits is almost usize::MAX this will overflow. - if bits % u32::BITS as usize == 0 { - bits / u32::BITS as usize + if bits % u32::BITS == 0 { + bits / u32::BITS } else { - bits / u32::BITS as usize + 1 + bits / u32::BITS + 1 } } /// Computes the bitmask for the final word of the vector fn mask_for_bits(bits: usize) -> u32 { // Note especially that a perfect multiple of u32::BITS should mask all 1s. - !0 >> (u32::BITS as usize - bits % u32::BITS as usize) % u32::BITS as usize + !0 >> (u32::BITS - bits % u32::BITS) % u32::BITS } impl BitVec { @@ -239,7 +239,7 @@ impl BitVec { /// An operation might screw up the unused bits in the last block of the /// `BitVec`. As per (3), it's assumed to be all 0s. This method fixes it up. fn fix_last_block(&mut self) { - let extra_bits = self.len() % u32::BITS as usize; + let extra_bits = self.len() % u32::BITS; if extra_bits > 0 { let mask = (1 << extra_bits) - 1; let storage_len = self.storage.len(); @@ -318,7 +318,7 @@ impl BitVec { /// false, false, true, false])); /// ``` pub fn from_bytes(bytes: &[u8]) -> BitVec { - let len = bytes.len().checked_mul(u8::BITS as usize).expect("capacity overflow"); + let len = bytes.len().checked_mul(u8::BITS).expect("capacity overflow"); let mut bit_vec = BitVec::with_capacity(len); let complete_words = bytes.len() / 4; let extra_bytes = bytes.len() % 4; @@ -387,8 +387,8 @@ impl BitVec { if i >= self.nbits { return None; } - let w = i / u32::BITS as usize; - let b = i % u32::BITS as usize; + let w = i / u32::BITS; + let b = i % u32::BITS; self.storage.get(w).map(|&block| (block & (1 << b)) != 0 ) @@ -415,8 +415,8 @@ impl BitVec { reason = "panic semantics are likely to change in the future")] pub fn set(&mut self, i: usize, x: bool) { assert!(i < self.nbits); - let w = i / u32::BITS as usize; - let b = i % u32::BITS as usize; + let w = i / u32::BITS; + let b = i % u32::BITS; let flag = 1 << b; let val = if x { self.storage[w] | flag } else { self.storage[w] & !flag }; @@ -812,7 +812,7 @@ impl BitVec { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn capacity(&self) -> usize { - self.storage.capacity().checked_mul(u32::BITS as usize).unwrap_or(usize::MAX) + self.storage.capacity().checked_mul(u32::BITS).unwrap_or(usize::MAX) } /// Grows the `BitVec` in-place, adding `n` copies of `value` to the `BitVec`. @@ -843,7 +843,7 @@ impl BitVec { // Correct the old tail word, setting or clearing formerly unused bits let num_cur_blocks = blocks_for_bits(self.nbits); - if self.nbits % u32::BITS as usize > 0 { + if self.nbits % u32::BITS > 0 { let mask = mask_for_bits(self.nbits); if value { self.storage[num_cur_blocks - 1] |= !mask; @@ -893,7 +893,7 @@ impl BitVec { // (3) self.set(i, false); self.nbits = i; - if self.nbits % u32::BITS as usize == 0 { + if self.nbits % u32::BITS == 0 { // (2) self.storage.pop(); } @@ -916,7 +916,7 @@ impl BitVec { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn push(&mut self, elem: bool) { - if self.nbits % u32::BITS as usize == 0 { + if self.nbits % u32::BITS == 0 { self.storage.push(0); } let insert_pos = self.nbits; @@ -1442,7 +1442,7 @@ impl BitSet { // Truncate let trunc_len = cmp::max(old_len - n, 1); bit_vec.storage.truncate(trunc_len); - bit_vec.nbits = trunc_len * u32::BITS as usize; + bit_vec.nbits = trunc_len * u32::BITS; } /// Iterator over each u32 stored in the `BitSet`. @@ -1880,13 +1880,13 @@ impl<'a> Iterator for TwoBitPositions<'a> { fn next(&mut self) -> Option { while self.next_idx < self.set.bit_vec.len() || self.next_idx < self.other.bit_vec.len() { - let bit_idx = self.next_idx % u32::BITS as usize; + let bit_idx = self.next_idx % u32::BITS; if bit_idx == 0 { let s_bit_vec = &self.set.bit_vec; let o_bit_vec = &self.other.bit_vec; // Merging the two words is a bit of an awkward dance since // one BitVec might be longer than the other - let word_idx = self.next_idx / u32::BITS as usize; + let word_idx = self.next_idx / u32::BITS; let w1 = if word_idx < s_bit_vec.storage.len() { s_bit_vec.storage[word_idx] } else { 0 }; diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index fe2efc7164d..ecf341a5ea6 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -83,7 +83,7 @@ pub trait CLike { fn bit(e: &E) -> usize { use core::usize; let value = e.to_usize(); - assert!(value < usize::BITS as usize, + assert!(value < usize::BITS, "EnumSet only supports up to {} variants.", usize::BITS - 1); 1 << value } -- cgit 1.4.1-3-g733a5