about summary refs log tree commit diff
path: root/src/libcollectionstest/bit
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-03 04:29:52 +0000
committerbors <bors@rust-lang.org>2015-04-03 04:29:52 +0000
commitfc98b19cf72ea45851ebb7b28af160be92b19128 (patch)
tree8a19d8c1f6e9a71eb5e0286954519b4b7ec3fbf8 /src/libcollectionstest/bit
parent5e30f05a05326018357c6fffdfb872e8a8d2367c (diff)
parent883adc6763c3dd06b282368698b28a07cdd65fd6 (diff)
downloadrust-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/libcollectionstest/bit')
-rw-r--r--src/libcollectionstest/bit/set.rs2
-rw-r--r--src/libcollectionstest/bit/vec.rs80
2 files changed, 41 insertions, 41 deletions
diff --git a/src/libcollectionstest/bit/set.rs b/src/libcollectionstest/bit/set.rs
index 19ea25ee345..10c688c3b66 100644
--- a/src/libcollectionstest/bit/set.rs
+++ b/src/libcollectionstest/bit/set.rs
@@ -407,7 +407,7 @@ mod bench {
         let mut bit_vec = BitSet::new();
         b.iter(|| {
             for _ in 0..100 {
-                bit_vec.insert((r.next_u32() as usize) % u32::BITS as usize);
+                bit_vec.insert((r.next_u32() as usize) % u32::BITS);
             }
             black_box(&bit_vec);
         });
diff --git a/src/libcollectionstest/bit/vec.rs b/src/libcollectionstest/bit/vec.rs
index 3826974d1ad..de3c0586ab7 100644
--- a/src/libcollectionstest/bit/vec.rs
+++ b/src/libcollectionstest/bit/vec.rs
@@ -541,43 +541,43 @@ fn test_big_bit_vec_tests() {
 
 #[test]
 fn test_bit_vec_push_pop() {
-    let mut s = BitVec::from_elem(5 * u32::BITS as usize - 2, false);
-    assert_eq!(s.len(), 5 * u32::BITS as usize - 2);
-    assert_eq!(s[5 * u32::BITS as usize - 3], false);
+    let mut s = BitVec::from_elem(5 * u32::BITS - 2, false);
+    assert_eq!(s.len(), 5 * u32::BITS - 2);
+    assert_eq!(s[5 * u32::BITS - 3], false);
     s.push(true);
     s.push(true);
-    assert_eq!(s[5 * u32::BITS as usize - 2], true);
-    assert_eq!(s[5 * u32::BITS as usize - 1], true);
+    assert_eq!(s[5 * u32::BITS - 2], true);
+    assert_eq!(s[5 * u32::BITS - 1], true);
     // Here the internal vector will need to be extended
     s.push(false);
-    assert_eq!(s[5 * u32::BITS as usize], false);
+    assert_eq!(s[5 * u32::BITS], false);
     s.push(false);
-    assert_eq!(s[5 * u32::BITS as usize + 1], false);
-    assert_eq!(s.len(), 5 * u32::BITS as usize + 2);
+    assert_eq!(s[5 * u32::BITS + 1], false);
+    assert_eq!(s.len(), 5 * u32::BITS + 2);
     // Pop it all off
     assert_eq!(s.pop(), Some(false));
     assert_eq!(s.pop(), Some(false));
     assert_eq!(s.pop(), Some(true));
     assert_eq!(s.pop(), Some(true));
-    assert_eq!(s.len(), 5 * u32::BITS as usize - 2);
+    assert_eq!(s.len(), 5 * u32::BITS - 2);
 }
 
 #[test]
 fn test_bit_vec_truncate() {
-    let mut s = BitVec::from_elem(5 * u32::BITS as usize, true);
+    let mut s = BitVec::from_elem(5 * u32::BITS, true);
 
-    assert_eq!(s, BitVec::from_elem(5 * u32::BITS as usize, true));
-    assert_eq!(s.len(), 5 * u32::BITS as usize);
-    s.truncate(4 * u32::BITS as usize);
-    assert_eq!(s, BitVec::from_elem(4 * u32::BITS as usize, true));
-    assert_eq!(s.len(), 4 * u32::BITS as usize);
+    assert_eq!(s, BitVec::from_elem(5 * u32::BITS, true));
+    assert_eq!(s.len(), 5 * u32::BITS);
+    s.truncate(4 * u32::BITS);
+    assert_eq!(s, BitVec::from_elem(4 * u32::BITS, true));
+    assert_eq!(s.len(), 4 * u32::BITS);
     // Truncating to a size > s.len() should be a noop
-    s.truncate(5 * u32::BITS as usize);
-    assert_eq!(s, BitVec::from_elem(4 * u32::BITS as usize, true));
-    assert_eq!(s.len(), 4 * u32::BITS as usize);
-    s.truncate(3 * u32::BITS as usize - 10);
-    assert_eq!(s, BitVec::from_elem(3 * u32::BITS as usize - 10, true));
-    assert_eq!(s.len(), 3 * u32::BITS as usize - 10);
+    s.truncate(5 * u32::BITS);
+    assert_eq!(s, BitVec::from_elem(4 * u32::BITS, true));
+    assert_eq!(s.len(), 4 * u32::BITS);
+    s.truncate(3 * u32::BITS - 10);
+    assert_eq!(s, BitVec::from_elem(3 * u32::BITS - 10, true));
+    assert_eq!(s.len(), 3 * u32::BITS - 10);
     s.truncate(0);
     assert_eq!(s, BitVec::from_elem(0, true));
     assert_eq!(s.len(), 0);
@@ -585,26 +585,26 @@ fn test_bit_vec_truncate() {
 
 #[test]
 fn test_bit_vec_reserve() {
-    let mut s = BitVec::from_elem(5 * u32::BITS as usize, true);
+    let mut s = BitVec::from_elem(5 * u32::BITS, true);
     // Check capacity
-    assert!(s.capacity() >= 5 * u32::BITS as usize);
-    s.reserve(2 * u32::BITS as usize);
-    assert!(s.capacity() >= 7 * u32::BITS as usize);
-    s.reserve(7 * u32::BITS as usize);
-    assert!(s.capacity() >= 12 * u32::BITS as usize);
-    s.reserve_exact(7 * u32::BITS as usize);
-    assert!(s.capacity() >= 12 * u32::BITS as usize);
-    s.reserve(7 * u32::BITS as usize + 1);
-    assert!(s.capacity() >= 12 * u32::BITS as usize + 1);
+    assert!(s.capacity() >= 5 * u32::BITS);
+    s.reserve(2 * u32::BITS);
+    assert!(s.capacity() >= 7 * u32::BITS);
+    s.reserve(7 * u32::BITS);
+    assert!(s.capacity() >= 12 * u32::BITS);
+    s.reserve_exact(7 * u32::BITS);
+    assert!(s.capacity() >= 12 * u32::BITS);
+    s.reserve(7 * u32::BITS + 1);
+    assert!(s.capacity() >= 12 * u32::BITS + 1);
     // Check that length hasn't changed
-    assert_eq!(s.len(), 5 * u32::BITS as usize);
+    assert_eq!(s.len(), 5 * u32::BITS);
     s.push(true);
     s.push(false);
     s.push(true);
-    assert_eq!(s[5 * u32::BITS as usize - 1], true);
-    assert_eq!(s[5 * u32::BITS as usize - 0], true);
-    assert_eq!(s[5 * u32::BITS as usize + 1], false);
-    assert_eq!(s[5 * u32::BITS as usize + 2], true);
+    assert_eq!(s[5 * u32::BITS - 1], true);
+    assert_eq!(s[5 * u32::BITS - 0], true);
+    assert_eq!(s[5 * u32::BITS + 1], false);
+    assert_eq!(s[5 * u32::BITS + 2], true);
 }
 
 #[test]
@@ -650,7 +650,7 @@ mod bench {
         let mut bit_vec = 0 as usize;
         b.iter(|| {
             for _ in 0..100 {
-                bit_vec |= 1 << ((r.next_u32() as usize) % u32::BITS as usize);
+                bit_vec |= 1 << ((r.next_u32() as usize) % u32::BITS);
             }
             black_box(&bit_vec);
         });
@@ -683,10 +683,10 @@ mod bench {
     #[bench]
     fn bench_bit_set_small(b: &mut Bencher) {
         let mut r = rng();
-        let mut bit_vec = BitVec::from_elem(u32::BITS as usize, false);
+        let mut bit_vec = BitVec::from_elem(u32::BITS, false);
         b.iter(|| {
             for _ in 0..100 {
-                bit_vec.set((r.next_u32() as usize) % u32::BITS as usize, true);
+                bit_vec.set((r.next_u32() as usize) % u32::BITS, true);
             }
             black_box(&bit_vec);
         });
@@ -703,7 +703,7 @@ mod bench {
 
     #[bench]
     fn bench_bit_vec_small_iter(b: &mut Bencher) {
-        let bit_vec = BitVec::from_elem(u32::BITS as usize, false);
+        let bit_vec = BitVec::from_elem(u32::BITS, false);
         b.iter(|| {
             let mut sum = 0;
             for _ in 0..10 {