@@ -130,32 +130,29 @@ struct Allocation {
130130/// padding occurs if the required size is smaller than the size of the aligned hole. All padding
131131/// must be at least `HoleList::min_size()` big or the hole is unusable.
132132fn split_hole ( hole : HoleInfo , required_size : usize , required_align : usize ) -> Option < Allocation > {
133+ let ( aligned_addr, front_padding) = if hole. addr == align_up ( hole. addr , required_align) {
134+ // hole has already the required alignment
135+ ( hole. addr , None )
136+ } else {
137+ // the required alignment causes some padding before the allocation
138+ let aligned_addr = align_up ( hole. addr + HoleList :: min_size ( ) , required_align) ;
139+ ( aligned_addr, Some ( HoleInfo {
140+ addr : hole. addr ,
141+ size : aligned_addr - hole. addr ,
142+ } ) )
143+ } ;
144+
133145 let aligned_hole = {
134- let aligned_hole_addr = align_up ( hole. addr , required_align) ;
135- if aligned_hole_addr + required_size > hole. addr + hole. size {
146+ if aligned_addr + required_size > hole. addr + hole. size {
136147 // hole is too small
137148 return None ;
138149 }
139150 HoleInfo {
140- addr : aligned_hole_addr ,
141- size : hole. size - ( aligned_hole_addr - hole. addr ) ,
151+ addr : aligned_addr ,
152+ size : hole. size - ( aligned_addr - hole. addr ) ,
142153 }
143154 } ;
144155
145- let front_padding = if aligned_hole. addr == hole. addr {
146- // hole has already the required alignment
147- None
148- } else if aligned_hole. addr < hole. addr + HoleList :: min_size ( ) {
149- // we can't use this hole because the required padding would create a new, too small hole
150- return None ;
151- } else {
152- // the required alignment causes some padding before the allocation
153- Some ( HoleInfo {
154- addr : hole. addr ,
155- size : aligned_hole. addr - hole. addr ,
156- } )
157- } ;
158-
159156 let back_padding = if aligned_hole. size == required_size {
160157 // the aligned hole has exactly the size that's needed, no padding accrues
161158 None
0 commit comments