diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-19 04:56:58 +0200 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-06-20 09:28:12 +0200 |
| commit | bf8f6c399b886480a2f2710531cf76de46b1c0cd (patch) | |
| tree | d6561f1a9d2f52b58aa41524ce29c9ce157b853f /src/liballoc | |
| parent | 2efbc9e5a2c5ae36ed2de0b23f315a5d6853b747 (diff) | |
| download | rust-bf8f6c399b886480a2f2710531cf76de46b1c0cd.tar.gz rust-bf8f6c399b886480a2f2710531cf76de46b1c0cd.zip | |
Rc: reduce duplicate calls.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 252b1c5a6dc..970b4745c31 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1674,14 +1674,16 @@ trait RcBoxPtr<T: ?Sized> { #[inline] fn inc_strong(&self) { + let strong = self.strong(); + // We want to abort on overflow instead of dropping the value. // The reference count will never be zero when this is called; // nevertheless, we insert an abort here to hint LLVM at // an otherwise missed optimization. - if self.strong() == 0 || self.strong() == usize::max_value() { + if strong == 0 || strong == usize::max_value() { unsafe { abort(); } } - self.inner().strong.set(self.strong() + 1); + self.inner().strong.set(strong + 1); } #[inline] @@ -1696,14 +1698,16 @@ trait RcBoxPtr<T: ?Sized> { #[inline] fn inc_weak(&self) { + let weak = self.weak(); + // We want to abort on overflow instead of dropping the value. // The reference count will never be zero when this is called; // nevertheless, we insert an abort here to hint LLVM at // an otherwise missed optimization. - if self.weak() == 0 || self.weak() == usize::max_value() { + if weak == 0 || weak == usize::max_value() { unsafe { abort(); } } - self.inner().weak.set(self.weak() + 1); + self.inner().weak.set(weak + 1); } #[inline] |
