@@ -244,7 +244,12 @@ impl Layout {
244244 . ok_or ( LayoutErr { private : ( ) } ) ?;
245245 let alloc_size = padded_size. checked_mul ( n)
246246 . ok_or ( LayoutErr { private : ( ) } ) ?;
247- Ok ( ( Layout :: from_size_align ( alloc_size, self . align ( ) ) ?, padded_size) )
247+
248+ unsafe {
249+ // self.align is already known to be valid and alloc_size has been
250+ // padded already.
251+ Ok ( ( Layout :: from_size_align_unchecked ( alloc_size, self . align ( ) ) , padded_size) )
252+ }
248253 }
249254
250255 /// Creates a layout describing the record for `self` followed by
@@ -258,11 +263,10 @@ impl Layout {
258263 /// (assuming that the record itself starts at offset 0).
259264 ///
260265 /// On arithmetic overflow, returns `LayoutErr`.
266+ #[ inline]
261267 pub fn extend ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
262268 let new_align = cmp:: max ( self . align ( ) , next. align ( ) ) ;
263- let realigned = Layout :: from_size_align ( self . size ( ) , new_align) ?;
264-
265- let pad = realigned. padding_needed_for ( next. align ( ) ) ;
269+ let pad = self . padding_needed_for ( next. align ( ) ) ;
266270
267271 let offset = self . size ( ) . checked_add ( pad)
268272 . ok_or ( LayoutErr { private : ( ) } ) ?;
@@ -285,6 +289,7 @@ impl Layout {
285289 /// aligned.
286290 ///
287291 /// On arithmetic overflow, returns `LayoutErr`.
292+ #[ inline]
288293 pub fn repeat_packed ( & self , n : usize ) -> Result < Self , LayoutErr > {
289294 let size = self . size ( ) . checked_mul ( n) . ok_or ( LayoutErr { private : ( ) } ) ?;
290295 Layout :: from_size_align ( size, self . align ( ) )
@@ -305,6 +310,7 @@ impl Layout {
305310 /// `extend`.)
306311 ///
307312 /// On arithmetic overflow, returns `LayoutErr`.
313+ #[ inline]
308314 pub fn extend_packed ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
309315 let new_size = self . size ( ) . checked_add ( next. size ( ) )
310316 . ok_or ( LayoutErr { private : ( ) } ) ?;
@@ -315,6 +321,7 @@ impl Layout {
315321 /// Creates a layout describing the record for a `[T; n]`.
316322 ///
317323 /// On arithmetic overflow, returns `LayoutErr`.
324+ #[ inline]
318325 pub fn array < T > ( n : usize ) -> Result < Self , LayoutErr > {
319326 Layout :: new :: < T > ( )
320327 . repeat ( n)
0 commit comments