Skip to content

Commit 0963f11

Browse files
committed
move unlikely intrinsics out of is_full
1 parent 9212e48 commit 0963f11

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/liballoc/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<T> Vec<T> {
710710

711711
#[inline(always)]
712712
fn is_full(&self) -> bool {
713-
unsafe { intrinsics::unlikely(self.len == self.buf.cap()) }
713+
self.len == self.buf.cap()
714714
}
715715

716716
/// Inserts an element at position `index` within the vector, shifting all
@@ -735,7 +735,7 @@ impl<T> Vec<T> {
735735
assert!(index <= len);
736736

737737
// space for the new element
738-
if self.is_full() {
738+
if unsafe { intrinsics::unlikely(self.is_full()) } {
739739
self.buf.grow_by(1);
740740
}
741741

@@ -972,7 +972,7 @@ impl<T> Vec<T> {
972972
pub fn push(&mut self, value: T) {
973973
// This will panic or abort if we would allocate > isize::MAX bytes
974974
// or if the length increment would overflow for zero-sized types.
975-
if self.is_full() {
975+
if unsafe { intrinsics::unlikely(self.is_full()) } {
976976
self.buf.grow_by(1);
977977
}
978978
unsafe {
@@ -2540,7 +2540,7 @@ impl<'a, T> Placer<T> for PlaceBack<'a, T> {
25402540
fn make_place(self) -> Self {
25412541
// This will panic or abort if we would allocate > isize::MAX bytes
25422542
// or if the length increment would overflow for zero-sized types.
2543-
if self.vec.is_full() {
2543+
if unsafe { intrinsics::unlikely(self.vec.is_full()) } {
25442544
self.vec.buf.grow_by(1);
25452545
}
25462546
self

src/liballoc/vec_deque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<T> VecDeque<T> {
140140
/// Returns `true` if and only if the buffer is at full capacity.
141141
#[inline]
142142
fn is_full(&self) -> bool {
143-
unsafe { intrinsics::unlikely(self.cap() - self.len() == 1) }
143+
self.cap() - self.len() == 1
144144
}
145145

146146
/// Returns the index in the underlying buffer for a given logical element
@@ -1753,7 +1753,7 @@ impl<T> VecDeque<T> {
17531753
// This may panic or abort
17541754
#[inline]
17551755
fn grow_if_necessary(&mut self) {
1756-
if self.is_full() {
1756+
if unsafe { intrinsics::unlikely(self.is_full()) } {
17571757
let old_cap = self.cap();
17581758
self.buf.grow_by(old_cap);
17591759
unsafe {

0 commit comments

Comments
 (0)