File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -235,11 +235,18 @@ impl Layout {
235235 #[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
236236 #[ inline]
237237 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:
239239 // > `size`, when rounded up to the nearest multiple of `align`,
240240 // > must not overflow (i.e., the rounded value must be less than
241241 // > `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+
243250 let alloc_size = padded_size. checked_mul ( n) . ok_or ( LayoutErr { private : ( ) } ) ?;
244251
245252 unsafe {
You can’t perform that action at this time.
0 commit comments