@@ -244,7 +244,12 @@ impl Layout {
244
244
. ok_or ( LayoutErr { private : ( ) } ) ?;
245
245
let alloc_size = padded_size. checked_mul ( n)
246
246
. 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
+ }
248
253
}
249
254
250
255
/// Creates a layout describing the record for `self` followed by
@@ -258,11 +263,10 @@ impl Layout {
258
263
/// (assuming that the record itself starts at offset 0).
259
264
///
260
265
/// On arithmetic overflow, returns `LayoutErr`.
266
+ #[ inline]
261
267
pub fn extend ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
262
268
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 ( ) ) ;
266
270
267
271
let offset = self . size ( ) . checked_add ( pad)
268
272
. ok_or ( LayoutErr { private : ( ) } ) ?;
@@ -285,6 +289,7 @@ impl Layout {
285
289
/// aligned.
286
290
///
287
291
/// On arithmetic overflow, returns `LayoutErr`.
292
+ #[ inline]
288
293
pub fn repeat_packed ( & self , n : usize ) -> Result < Self , LayoutErr > {
289
294
let size = self . size ( ) . checked_mul ( n) . ok_or ( LayoutErr { private : ( ) } ) ?;
290
295
Layout :: from_size_align ( size, self . align ( ) )
@@ -305,6 +310,7 @@ impl Layout {
305
310
/// `extend`.)
306
311
///
307
312
/// On arithmetic overflow, returns `LayoutErr`.
313
+ #[ inline]
308
314
pub fn extend_packed ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
309
315
let new_size = self . size ( ) . checked_add ( next. size ( ) )
310
316
. ok_or ( LayoutErr { private : ( ) } ) ?;
@@ -315,6 +321,7 @@ impl Layout {
315
321
/// Creates a layout describing the record for a `[T; n]`.
316
322
///
317
323
/// On arithmetic overflow, returns `LayoutErr`.
324
+ #[ inline]
318
325
pub fn array < T > ( n : usize ) -> Result < Self , LayoutErr > {
319
326
Layout :: new :: < T > ( )
320
327
. repeat ( n)
0 commit comments