diff options
| author | bors <bors@rust-lang.org> | 2015-04-03 04:29:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-04-03 04:29:52 +0000 |
| commit | fc98b19cf72ea45851ebb7b28af160be92b19128 (patch) | |
| tree | 8a19d8c1f6e9a71eb5e0286954519b4b7ec3fbf8 /src/libcollections | |
| parent | 5e30f05a05326018357c6fffdfb872e8a8d2367c (diff) | |
| parent | 883adc6763c3dd06b282368698b28a07cdd65fd6 (diff) | |
| download | rust-fc98b19cf72ea45851ebb7b28af160be92b19128.tar.gz rust-fc98b19cf72ea45851ebb7b28af160be92b19128.zip | |
Auto merge of #23832 - petrochenkov:usize, r=aturon
These constants are small and can fit even in `u8`, but semantically they have type `usize` because they denote sizes and are almost always used in `usize` context. The change of their type to `u32` during the integer audit led only to the large amount of `as usize` noise (see the second commit, which removes this noise). This is a minor [breaking-change] to an unstable interface. r? @aturon
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/bit.rs | 34 | ||||
| -rw-r--r-- | src/libcollections/enum_set.rs | 2 |
2 files changed, 18 insertions, 18 deletions
diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 8874ac6eb87..d9255241af0 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -190,17 +190,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 { @@ -238,7 +238,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(); @@ -317,7 +317,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; @@ -386,8 +386,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 ) @@ -414,8 +414,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 }; @@ -811,7 +811,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`. @@ -842,7 +842,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; @@ -892,7 +892,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(); } @@ -915,7 +915,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; @@ -1433,7 +1433,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`. @@ -1871,13 +1871,13 @@ impl<'a> Iterator for TwoBitPositions<'a> { fn next(&mut self) -> Option<usize> { 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 0b206d381dd..a3a266669b1 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -86,7 +86,7 @@ pub trait CLike { fn bit<E:CLike>(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 } |
