From 1553ea23165fc795b8c7e8188d2782c39c94b922 Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Sat, 4 Aug 2018 01:49:36 -0400 Subject: Changed `Rc::inc_{weak,strong}` to better hint optimization to LLVM --- src/liballoc/rc.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index be049eb6e5e..aec60bc18f9 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1359,7 +1359,14 @@ trait RcBoxPtr { #[inline] fn inc_strong(&self) { - self.inner().strong.set(self.strong().checked_add(1).unwrap_or_else(|| unsafe { abort() })); + // 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 missied optimization. + if self.strong() == 0 || self.strong() == usize::max_value() { + unsafe { abort(); } + } + self.inner().strong.set(self.strong() + 1); } #[inline] @@ -1374,7 +1381,14 @@ trait RcBoxPtr { #[inline] fn inc_weak(&self) { - self.inner().weak.set(self.weak().checked_add(1).unwrap_or_else(|| unsafe { abort() })); + // 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 missied optimization. + if self.weak() == 0 || self.weak() == usize::max_value() { + unsafe { abort(); } + } + self.inner().weak.set(self.weak() + 1); } #[inline] -- cgit 1.4.1-3-g733a5 From 4e17fbde0b02b0b818b9a6c6fcf2d18eb02622d8 Mon Sep 17 00:00:00 2001 From: Dmytro Shynkevych Date: Sun, 5 Aug 2018 02:41:14 -0400 Subject: Fixed typo --- src/liballoc/rc.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index aec60bc18f9..82e1c92359c 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1362,7 +1362,7 @@ trait RcBoxPtr { // 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 missied optimization. + // an otherwise missed optimization. if self.strong() == 0 || self.strong() == usize::max_value() { unsafe { abort(); } } @@ -1384,7 +1384,7 @@ trait RcBoxPtr { // 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 missied optimization. + // an otherwise missed optimization. if self.weak() == 0 || self.weak() == usize::max_value() { unsafe { abort(); } } -- cgit 1.4.1-3-g733a5