diff options
| author | James Miller <james@aatch.net> | 2015-01-21 09:56:59 +1300 |
|---|---|---|
| committer | James Miller <james@aatch.net> | 2015-01-21 09:56:59 +1300 |
| commit | a7525bc4c8eb8507a5c248d29286e77133217cf3 (patch) | |
| tree | 611f731e8167160457938baa86b610e172b266e7 /src/liballoc | |
| parent | 9bbfd681c9fa47f462a89e8f5eedd3fa2a5de2e7 (diff) | |
| download | rust-a7525bc4c8eb8507a5c248d29286e77133217cf3.tar.gz rust-a7525bc4c8eb8507a5c248d29286e77133217cf3.zip | |
Add more explanation for why the assumes are there
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 837d709e882..e651e375e3d 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -909,6 +909,8 @@ trait RcBoxPtr<T> { fn inc_strong(&self) { let strong = self.strong(); // The reference count is always at least one unless we're about to drop the type + // This allows the bulk of the destructor to be omitted in cases where we know that + // the reference count must be > 0. unsafe { assume(strong > 0); } self.inner().strong.set(strong + 1); } @@ -917,6 +919,8 @@ trait RcBoxPtr<T> { fn dec_strong(&self) { let strong = self.strong(); // The reference count is always at least one unless we're about to drop the type + // This allows the bulk of the destructor to be omitted in cases where we know that + // the reference count must be > 0 unsafe { assume(strong > 0); } self.inner().strong.set(strong - 1); } @@ -936,7 +940,9 @@ impl<T> RcBoxPtr<T> for Rc<T> { fn inner(&self) -> &RcBox<T> { unsafe { // Safe to assume this here, as if it weren't true, we'd be breaking - // the contract anyway + // the contract anyway. + // This allows the null check to be elided in the destructor if we + // manipulated the reference count in the same function. assume(!self._ptr.is_null()); &(**self._ptr) } @@ -949,6 +955,8 @@ impl<T> RcBoxPtr<T> for Weak<T> { unsafe { // Safe to assume this here, as if it weren't true, we'd be breaking // the contract anyway + // This allows the null check to be elided in the destructor if we + // manipulated the reference count in the same function. assume(!self._ptr.is_null()); &(**self._ptr) } |
