Skip to content

Commit bf8f6c3

Browse files
committed
Rc: reduce duplicate calls.
1 parent 2efbc9e commit bf8f6c3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/liballoc/rc.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,14 +1674,16 @@ trait RcBoxPtr<T: ?Sized> {
16741674

16751675
#[inline]
16761676
fn inc_strong(&self) {
1677+
let strong = self.strong();
1678+
16771679
// We want to abort on overflow instead of dropping the value.
16781680
// The reference count will never be zero when this is called;
16791681
// nevertheless, we insert an abort here to hint LLVM at
16801682
// an otherwise missed optimization.
1681-
if self.strong() == 0 || self.strong() == usize::max_value() {
1683+
if strong == 0 || strong == usize::max_value() {
16821684
unsafe { abort(); }
16831685
}
1684-
self.inner().strong.set(self.strong() + 1);
1686+
self.inner().strong.set(strong + 1);
16851687
}
16861688

16871689
#[inline]
@@ -1696,14 +1698,16 @@ trait RcBoxPtr<T: ?Sized> {
16961698

16971699
#[inline]
16981700
fn inc_weak(&self) {
1701+
let weak = self.weak();
1702+
16991703
// We want to abort on overflow instead of dropping the value.
17001704
// The reference count will never be zero when this is called;
17011705
// nevertheless, we insert an abort here to hint LLVM at
17021706
// an otherwise missed optimization.
1703-
if self.weak() == 0 || self.weak() == usize::max_value() {
1707+
if weak == 0 || weak == usize::max_value() {
17041708
unsafe { abort(); }
17051709
}
1706-
self.inner().weak.set(self.weak() + 1);
1710+
self.inner().weak.set(weak + 1);
17071711
}
17081712

17091713
#[inline]

0 commit comments

Comments
 (0)