Skip to content

Commit ebab7b3

Browse files
committed
move unlikely intrinsics out of is_full
1 parent a52f06e commit ebab7b3

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

@@ -970,7 +970,7 @@ impl<T> Vec<T> {
970970
pub fn push(&mut self, value: T) {
971971
// This will panic or abort if we would allocate > isize::MAX bytes
972972
// or if the length increment would overflow for zero-sized types.
973-
if self.is_full() {
973+
if unsafe { intrinsics::unlikely(self.is_full()) } {
974974
self.buf.grow_by(1);
975975
}
976976
unsafe {
@@ -2538,7 +2538,7 @@ impl<'a, T> Placer<T> for PlaceBack<'a, T> {
25382538
fn make_place(self) -> Self {
25392539
// This will panic or abort if we would allocate > isize::MAX bytes
25402540
// or if the length increment would overflow for zero-sized types.
2541-
if self.vec.is_full() {
2541+
if unsafe { intrinsics::unlikely(self.vec.is_full()) } {
25422542
self.vec.buf.grow_by(1);
25432543
}
25442544
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)