about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgnzlbg <gonzalobg88@gmail.com>2018-06-02 16:11:57 +0200
committergnzlbg <gonzalobg88@gmail.com>2018-06-02 16:46:25 +0200
commit2d7cd70b1ac0dc1ce3a2602b51301dedae6a25a6 (patch)
treec9fb87fd2d351d95172e76f2c2e9be386d87dd89
parent6ff67ee0d7b4f9f962809a82d9078f353e200818 (diff)
downloadrust-2d7cd70b1ac0dc1ce3a2602b51301dedae6a25a6.tar.gz
rust-2d7cd70b1ac0dc1ce3a2602b51301dedae6a25a6.zip
add missing inline's and optimizations
-rw-r--r--src/libcore/alloc.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs
index cddd142045a..4a817ebc43b 100644
--- a/src/libcore/alloc.rs
+++ b/src/libcore/alloc.rs
@@ -244,7 +244,12 @@ impl Layout {
             .ok_or(LayoutErr { private: () })?;
         let alloc_size = padded_size.checked_mul(n)
             .ok_or(LayoutErr { private: () })?;
-        Ok((Layout::from_size_align(alloc_size, self.align())?, padded_size))
+
+        unsafe {
+            // self.align is already known to be valid and alloc_size has been
+            // padded already.
+            Ok((Layout::from_size_align_unchecked(alloc_size, self.align()), padded_size))
+        }
     }
 
     /// Creates a layout describing the record for `self` followed by
@@ -258,11 +263,10 @@ impl Layout {
     /// (assuming that the record itself starts at offset 0).
     ///
     /// On arithmetic overflow, returns `LayoutErr`.
+    #[inline]
     pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutErr> {
         let new_align = cmp::max(self.align(), next.align());
-        let realigned = Layout::from_size_align(self.size(), new_align)?;
-
-        let pad = realigned.padding_needed_for(next.align());
+        let pad = self.padding_needed_for(next.align());
 
         let offset = self.size().checked_add(pad)
             .ok_or(LayoutErr { private: () })?;
@@ -285,6 +289,7 @@ impl Layout {
     /// aligned.
     ///
     /// On arithmetic overflow, returns `LayoutErr`.
+    #[inline]
     pub fn repeat_packed(&self, n: usize) -> Result<Self, LayoutErr> {
         let size = self.size().checked_mul(n).ok_or(LayoutErr { private: () })?;
         Layout::from_size_align(size, self.align())
@@ -305,6 +310,7 @@ impl Layout {
     ///  `extend`.)
     ///
     /// On arithmetic overflow, returns `LayoutErr`.
+    #[inline]
     pub fn extend_packed(&self, next: Self) -> Result<(Self, usize), LayoutErr> {
         let new_size = self.size().checked_add(next.size())
             .ok_or(LayoutErr { private: () })?;
@@ -315,6 +321,7 @@ impl Layout {
     /// Creates a layout describing the record for a `[T; n]`.
     ///
     /// On arithmetic overflow, returns `LayoutErr`.
+    #[inline]
     pub fn array<T>(n: usize) -> Result<Self, LayoutErr> {
         Layout::new::<T>()
             .repeat(n)