From 360f2f036d14889f4de37a8b4b6aad0d09772aad Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 31 Mar 2018 23:19:02 +0200 Subject: 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 `>::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 `>::shrink_to_fit` and mark it as `#[inline]` too. --- src/liballoc/string.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/liballoc/string.rs') diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index aa202e23628..95d5b30b67d 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1587,6 +1587,7 @@ impl String { /// let b = s.into_boxed_str(); /// ``` #[stable(feature = "box_str", since = "1.4.0")] + #[inline] pub fn into_boxed_str(self) -> Box { let slice = self.vec.into_boxed_slice(); unsafe { from_boxed_utf8_unchecked(slice) } -- cgit 1.4.1-3-g733a5