diff options
| author | kennytm <kennytm@gmail.com> | 2018-04-17 01:50:56 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-17 01:50:56 +0800 |
| commit | bf602952116262f261eec20a2dc085d915de7bc7 (patch) | |
| tree | 8fd11451918910559d4024bd11630fab46caf821 /src/liballoc/str.rs | |
| parent | 1ef1563518d48ad9231b3ec3ac463d34d819ed28 (diff) | |
| parent | b59fa0d9e81fe36c5d298f8f828aaf0755e96f89 (diff) | |
| download | rust-bf602952116262f261eec20a2dc085d915de7bc7.tar.gz rust-bf602952116262f261eec20a2dc085d915de7bc7.zip | |
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.
Diffstat (limited to 'src/liballoc/str.rs')
| -rw-r--r-- | src/liballoc/str.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 6c9f3dd7ec9..0e708465332 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -1827,6 +1827,7 @@ impl str { /// assert_eq!(*boxed_bytes, *s.as_bytes()); /// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] + #[inline] pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> { self.into() } @@ -2065,6 +2066,7 @@ impl str { /// assert_eq!(boxed_str.into_string(), string); /// ``` #[stable(feature = "box_str", since = "1.4.0")] + #[inline] pub fn into_string(self: Box<str>) -> String { let slice = Box::<[u8]>::from(self); unsafe { String::from_utf8_unchecked(slice.into_vec()) } @@ -2323,6 +2325,7 @@ impl str { /// assert_eq!("☺", &*smile); /// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] +#[inline] pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> { Box::from_raw(Box::into_raw(v) as *mut str) } |
