diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cell.rs | 29 | ||||
| -rw-r--r-- | src/libstd/hash/mod.rs | 3 | ||||
| -rw-r--r-- | src/libstd/option.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rc.rs | 25 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 2 |
5 files changed, 20 insertions, 43 deletions
diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index b54396efec5..d09b31faa25 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -176,8 +176,7 @@ impl<T> RefCell<T> { /// Fails if the value is currently borrowed. #[inline] pub fn set(&self, value: T) { - let mut reference = self.borrow_mut(); - *reference.get() = value; + *self.borrow_mut() = value; } } @@ -189,23 +188,19 @@ impl<T:Clone> RefCell<T> { /// Fails if the value is currently mutably borrowed. #[inline] pub fn get(&self) -> T { - let reference = self.borrow(); - (*reference.get()).clone() + (*self.borrow()).clone() } } impl<T: Clone> Clone for RefCell<T> { fn clone(&self) -> RefCell<T> { - let x = self.borrow(); - RefCell::new(x.get().clone()) + RefCell::new(self.get()) } } impl<T: Eq> Eq for RefCell<T> { fn eq(&self, other: &RefCell<T>) -> bool { - let a = self.borrow(); - let b = other.borrow(); - a.get() == b.get() + *self.borrow() == *other.borrow() } } @@ -222,14 +217,6 @@ impl<'b, T> Drop for Ref<'b, T> { } } -impl<'b, T> Ref<'b, T> { - /// Retrieve an immutable reference to the stored value. - #[inline] - pub fn get<'a>(&'a self) -> &'a T { - unsafe{ &*self.parent.value.get() } - } -} - impl<'b, T> Deref<T> for Ref<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { @@ -250,14 +237,6 @@ impl<'b, T> Drop for RefMut<'b, T> { } } -impl<'b, T> RefMut<'b, T> { - /// Retrieve a mutable reference to the stored value. - #[inline] - pub fn get<'a>(&'a mut self) -> &'a mut T { - unsafe{ &mut *self.parent.value.get() } - } -} - impl<'b, T> Deref<T> for RefMut<'b, T> { #[inline] fn deref<'a>(&'a self) -> &'a T { diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index 3791aa38b82..dc7d5c5b9c7 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -66,7 +66,6 @@ use container::Container; use io::Writer; use iter::Iterator; -use ops::Deref; use option::{Option, Some, None}; use rc::Rc; use str::{Str, StrSlice}; @@ -247,7 +246,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for @T { impl<S: Writer, T: Hash<S>> Hash<S> for Rc<T> { #[inline] fn hash(&self, state: &mut S) { - self.deref().hash(state); + (**self).hash(state); } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index 5f733302d6f..23363a97845 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -650,7 +650,7 @@ mod tests { #[unsafe_destructor] impl ::ops::Drop for R { fn drop(&mut self) { - let ii = self.i.deref(); + let ii = &*self.i; ii.set(ii.get() + 1); } } @@ -667,7 +667,7 @@ mod tests { let opt = Some(x); let _y = opt.unwrap(); } - assert_eq!(i.deref().get(), 1); + assert_eq!(i.get(), 1); } #[test] diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 03be4fea5ee..8dd06cb9232 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -122,24 +122,23 @@ impl<T> Clone for Rc<T> { impl<T: Eq> Eq for Rc<T> { #[inline(always)] - fn eq(&self, other: &Rc<T>) -> bool { *self.deref() == *other.deref() } - + fn eq(&self, other: &Rc<T>) -> bool { **self == **other } #[inline(always)] - fn ne(&self, other: &Rc<T>) -> bool { *self.deref() != *other.deref() } + fn ne(&self, other: &Rc<T>) -> bool { **self != **other } } impl<T: Ord> Ord for Rc<T> { #[inline(always)] - fn lt(&self, other: &Rc<T>) -> bool { *self.deref() < *other.deref() } + fn lt(&self, other: &Rc<T>) -> bool { **self < **other } #[inline(always)] - fn le(&self, other: &Rc<T>) -> bool { *self.deref() <= *other.deref() } + fn le(&self, other: &Rc<T>) -> bool { **self <= **other } #[inline(always)] - fn gt(&self, other: &Rc<T>) -> bool { *self.deref() > *other.deref() } + fn gt(&self, other: &Rc<T>) -> bool { **self > **other } #[inline(always)] - fn ge(&self, other: &Rc<T>) -> bool { *self.deref() >= *other.deref() } + fn ge(&self, other: &Rc<T>) -> bool { **self >= **other } } /// Weak reference to a reference-counted box @@ -236,21 +235,21 @@ mod tests { #[test] fn test_simple() { let x = Rc::new(5); - assert_eq!(*x.deref(), 5); + assert_eq!(*x, 5); } #[test] fn test_simple_clone() { let x = Rc::new(5); let y = x.clone(); - assert_eq!(*x.deref(), 5); - assert_eq!(*y.deref(), 5); + assert_eq!(*x, 5); + assert_eq!(*y, 5); } #[test] fn test_destructor() { let x = Rc::new(~5); - assert_eq!(**x.deref(), 5); + assert_eq!(**x, 5); } #[test] @@ -273,7 +272,7 @@ mod tests { // see issue #11532 use gc::Gc; let a = Rc::new(RefCell::new(Gc::new(1))); - assert!(a.deref().try_borrow_mut().is_some()); + assert!(a.try_borrow_mut().is_some()); } #[test] @@ -284,7 +283,7 @@ mod tests { let a = Rc::new(Cycle { x: RefCell::new(None) }); let b = a.clone().downgrade(); - *a.deref().x.borrow_mut().get() = Some(b); + *a.x.borrow_mut() = Some(b); // hopefully we don't double-free (or leak)... } diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 8c617c1b59b..f6d4579156e 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -471,7 +471,7 @@ mod test { { let mut a = a.borrow_mut(); - a.get().next = Some(b); + a.next = Some(b); } } |
