Skip to content

Commit

Permalink
Avoid using map_err
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Aug 7, 2021
1 parent e7f1c8e commit 03498aa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,12 @@ impl<T, A: Allocator> RawVec<T, A> {
// `Layout::array` cannot overflow here because it would have
// owerflown earlier when capacity was larger.
let new_layout = Layout::array::<T>(amount).unwrap_unchecked();
self.alloc
.shrink(ptr, layout, new_layout)
.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () })?
// We avoid `map_err` here because it bloats the amount of LLVM IR
// generated.
match self.alloc.shrink(ptr, layout, new_layout) {
Ok(ptr) => ptr,
Err(_) => Err(AllocError { layout: new_layout, non_exhaustive: () })?,
}
};
self.set_ptr(ptr);
Ok(())
Expand Down

0 comments on commit 03498aa

Please sign in to comment.