Skip to content

Commit 3e1cf5b

Browse files
committed
Hint optimizer about reserved capacity
1 parent fee5518 commit 3e1cf5b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

library/alloc/src/raw_vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ impl<T, A: Allocator> RawVec<T, A> {
292292
if self.needs_to_grow(len, additional) {
293293
do_reserve_and_handle(self, len, additional);
294294
}
295+
296+
unsafe {
297+
// Inform the optimizer that the reservation has succeeded or wasn't needed
298+
core::intrinsics::assume(!self.needs_to_grow(len, additional));
299+
}
295300
}
296301

297302
/// A specialized version of `reserve()` used only by the hot and
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
thread 'main' panicked at library/alloc/src/raw_vec.rs:545:5:
1+
thread 'main' panicked at library/alloc/src/raw_vec.rs:550:5:
22
capacity overflow
33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)