diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-04-21 17:58:52 -0400 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-24 17:18:48 -0700 |
| commit | 9e3d0b002a5c2e81d43351c9b8550a3f4ccfb8f9 (patch) | |
| tree | 1e9a15e8a55cc3947025ab3ac044c2f7977159d9 /src/libsync/deque.rs | |
| parent | f7f95c8f5a6294f161800dbb65a0423bb5248f34 (diff) | |
librustc: Remove the fallback to `int` from typechecking.
This breaks a fair amount of code. The typical patterns are:
* `for _ in range(0, 10)`: change to `for _ in range(0u, 10)`;
* `println!("{}", 3)`: change to `println!("{}", 3i)`;
* `[1, 2, 3].len()`: change to `[1i, 2, 3].len()`.
RFC #30. Closes #6023.
[breaking-change]
Diffstat (limited to 'src/libsync/deque.rs')
| -rw-r--r-- | src/libsync/deque.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/libsync/deque.rs b/src/libsync/deque.rs index f0184dc8164..18608a0a370 100644 --- a/src/libsync/deque.rs +++ b/src/libsync/deque.rs @@ -72,7 +72,7 @@ static K: int = 4; // size. // // The size in question is 1 << MIN_BITS -static MIN_BITS: int = 7; +static MIN_BITS: uint = 7; struct Deque<T> { bottom: AtomicInt, @@ -138,7 +138,7 @@ pub struct BufferPool<T> { /// LLVM is probably pretty good at doing this already. struct Buffer<T> { storage: *T, - log_size: int, + log_size: uint, } impl<T: Send> BufferPool<T> { @@ -157,7 +157,7 @@ impl<T: Send> BufferPool<T> { Stealer { deque: b, noshare: marker::NoShare }) } - fn alloc(&self, bits: int) -> Box<Buffer<T>> { + fn alloc(&mut self, bits: uint) -> Box<Buffer<T>> { unsafe { let mut pool = self.pool.lock(); match pool.iter().position(|x| x.size() >= (1 << bits)) { @@ -225,7 +225,7 @@ impl<T: Send> Clone for Stealer<T> { // personally going to heavily comment what's going on here. impl<T: Send> Deque<T> { - fn new(pool: BufferPool<T>) -> Deque<T> { + fn new(mut pool: BufferPool<T>) -> Deque<T> { let buf = pool.alloc(MIN_BITS); Deque { bottom: AtomicInt::new(0), @@ -345,12 +345,12 @@ impl<T: Send> Drop for Deque<T> { } #[inline] -fn buffer_alloc_size<T>(log_size: int) -> uint { +fn buffer_alloc_size<T>(log_size: uint) -> uint { (1 << log_size) * size_of::<T>() } impl<T: Send> Buffer<T> { - unsafe fn new(log_size: int) -> Buffer<T> { + unsafe fn new(log_size: uint) -> Buffer<T> { let size = buffer_alloc_size::<T>(log_size); let buffer = allocate(size, min_align_of::<T>()); Buffer { @@ -383,7 +383,10 @@ impl<T: Send> Buffer<T> { // Again, unsafe because this has incredibly dubious ownership violations. // It is assumed that this buffer is immediately dropped. unsafe fn resize(&self, b: int, t: int, delta: int) -> Buffer<T> { - let buf = Buffer::new(self.log_size + delta); + // NB: not entirely obvious, but thanks to 2's complement, + // casting delta to uint and then adding gives the desired + // effect. + let buf = Buffer::new(self.log_size + delta as uint); for i in range(t, b) { buf.put(i, self.get(i)); } @@ -419,7 +422,7 @@ mod tests { let (w, s) = pool.deque(); assert_eq!(w.pop(), None); assert_eq!(s.steal(), Empty); - w.push(1); + w.push(1i); assert_eq!(w.pop(), Some(1)); w.push(1); assert_eq!(s.steal(), Data(1)); @@ -564,7 +567,7 @@ mod tests { let mut rng = rand::task_rng(); let mut expected = 0; while expected < AMT { - if rng.gen_range(0, 3) == 2 { + if rng.gen_range(0i, 3) == 2 { match w.pop() { None => {} Some(2) => unsafe { HITS.fetch_add(1, SeqCst); }, @@ -629,7 +632,7 @@ mod tests { let mut myhit = false; 'outer: loop { for _ in range(0, rng.gen_range(0, AMT)) { - if !myhit && rng.gen_range(0, 3) == 2 { + if !myhit && rng.gen_range(0i, 3) == 2 { match w.pop() { None => {} Some((1, 2)) => myhit = true, |
