mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 01:42:54 +03:00
Rollup merge of #49555 - nox:inline-into-boxed, r=alexcrichton
Inline most of the code paths for conversions with boxed slices This helps with the specific problem described in #49541, obviously without making any large change to how inlining works in the general case. Everything involved in the conversions is made `#[inline]`, except for the `<Vec<T>>::into_boxed_slice` entry point which is made `#[inline(always)]` after checking that duplicating the function mentioned in the issue prevented its inlining if I only annotate it with `#[inline]`. For the record, that function was: ```rust pub fn foo() -> Box<[u8]> { vec![0].into_boxed_slice() } ``` To help the inliner's job, we also hoist a `self.capacity() != self.len` check in `<Vec<T>>::shrink_to_fit` and mark it as `#[inline]` too.
This commit is contained in:
@@ -1586,6 +1586,7 @@ pub fn replace_range<R>(&mut self, range: R, replace_with: &str)
|
||||
/// let b = s.into_boxed_str();
|
||||
/// ```
|
||||
#[stable(feature = "box_str", since = "1.4.0")]
|
||||
#[inline]
|
||||
pub fn into_boxed_str(self) -> Box<str> {
|
||||
let slice = self.vec.into_boxed_slice();
|
||||
unsafe { from_boxed_utf8_unchecked(slice) }
|
||||
|
||||
Reference in New Issue
Block a user