about summary refs log tree commit diff
path: root/src/liballoc/boxed.rs
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-04-17 01:50:56 +0800
committerGitHub <noreply@github.com>2018-04-17 01:50:56 +0800
commitbf602952116262f261eec20a2dc085d915de7bc7 (patch)
tree8fd11451918910559d4024bd11630fab46caf821 /src/liballoc/boxed.rs
parent1ef1563518d48ad9231b3ec3ac463d34d819ed28 (diff)
parentb59fa0d9e81fe36c5d298f8f828aaf0755e96f89 (diff)
downloadrust-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/boxed.rs')
-rw-r--r--src/liballoc/boxed.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index aceb6ff8abe..5ebd2cc6146 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -429,6 +429,7 @@ impl<'a, T: Copy> From<&'a [T]> for Box<[T]> {
 
 #[stable(feature = "box_from_slice", since = "1.17.0")]
 impl<'a> From<&'a str> for Box<str> {
+    #[inline]
     fn from(s: &'a str) -> Box<str> {
         unsafe { from_boxed_utf8_unchecked(Box::from(s.as_bytes())) }
     }
@@ -436,6 +437,7 @@ impl<'a> From<&'a str> for Box<str> {
 
 #[stable(feature = "boxed_str_conv", since = "1.19.0")]
 impl From<Box<str>> for Box<[u8]> {
+    #[inline]
     fn from(s: Box<str>) -> Self {
         unsafe { Box::from_raw(Box::into_raw(s) as *mut [u8]) }
     }