File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -235,11 +235,18 @@ impl Layout {
235
235
#[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
236
236
#[ inline]
237
237
pub fn repeat ( & self , n : usize ) -> Result < ( Self , usize ) , LayoutErr > {
238
- // This cannot overflow. Quoting from the invariant of Layout:
238
+ // `padded_size` cannot overflow. Quoting from the invariant of Layout:
239
239
// > `size`, when rounded up to the nearest multiple of `align`,
240
240
// > must not overflow (i.e., the rounded value must be less than
241
241
// > `usize::MAX`)
242
- let padded_size = self . size ( ) + self . padding_needed_for ( self . align ( ) ) ;
242
+ //
243
+ // However, replacing this line with an `unchecked_add` or a regular `+`
244
+ // operator caused a noticeable slowdown, see #69710.
245
+ let padded_size = self
246
+ . size ( )
247
+ . checked_add ( self . padding_needed_for ( self . align ( ) ) )
248
+ . ok_or ( LayoutErr { private : ( ) } ) ?;
249
+
243
250
let alloc_size = padded_size. checked_mul ( n) . ok_or ( LayoutErr { private : ( ) } ) ?;
244
251
245
252
unsafe {
You can’t perform that action at this time.
0 commit comments