@@ -171,6 +171,8 @@ mod imp {
171
171
#[ cfg( windows) ]
172
172
#[ allow( bad_style) ]
173
173
mod imp {
174
+ use core:: cmp:: min;
175
+ use core:: ptr:: copy_nonoverlapping;
174
176
use MIN_ALIGN ;
175
177
176
178
type LPVOID = * mut u8 ;
@@ -225,19 +227,16 @@ mod imp {
225
227
allocate_with_flags ( size, align, HEAP_ZERO_MEMORY )
226
228
}
227
229
228
- pub unsafe fn reallocate ( ptr : * mut u8 , _old_size : usize , size : usize , align : usize ) -> * mut u8 {
230
+ pub unsafe fn reallocate ( ptr : * mut u8 , old_size : usize , size : usize , align : usize ) -> * mut u8 {
229
231
if align <= MIN_ALIGN {
230
232
HeapReAlloc ( GetProcessHeap ( ) , 0 , ptr as LPVOID , size as SIZE_T ) as * mut u8
231
233
} else {
232
- let header = get_header ( ptr) ;
233
- let new = HeapReAlloc ( GetProcessHeap ( ) ,
234
- 0 ,
235
- header. 0 as LPVOID ,
236
- ( size + align) as SIZE_T ) as * mut u8 ;
237
- if new. is_null ( ) {
238
- return new;
234
+ let new = allocate ( size, align) ;
235
+ if !new. is_null ( ) {
236
+ copy_nonoverlapping ( ptr, new, min ( size, old_size) ) ;
237
+ deallocate ( ptr, old_size, align) ;
239
238
}
240
- align_ptr ( new, align )
239
+ new
241
240
}
242
241
}
243
242
@@ -246,15 +245,19 @@ mod imp {
246
245
size : usize ,
247
246
align : usize )
248
247
-> usize {
249
- if align <= MIN_ALIGN {
250
- let new = HeapReAlloc ( GetProcessHeap ( ) ,
251
- HEAP_REALLOC_IN_PLACE_ONLY ,
252
- ptr as LPVOID ,
253
- size as SIZE_T ) as * mut u8 ;
254
- if new. is_null ( ) { old_size } else { size }
248
+ let new = if align <= MIN_ALIGN {
249
+ HeapReAlloc ( GetProcessHeap ( ) ,
250
+ HEAP_REALLOC_IN_PLACE_ONLY ,
251
+ ptr as LPVOID ,
252
+ size as SIZE_T ) as * mut u8
255
253
} else {
256
- old_size
257
- }
254
+ let header = get_header ( ptr) ;
255
+ HeapReAlloc ( GetProcessHeap ( ) ,
256
+ HEAP_REALLOC_IN_PLACE_ONLY ,
257
+ header. 0 as LPVOID ,
258
+ size + align as SIZE_T ) as * mut u8
259
+ } ;
260
+ if new. is_null ( ) { old_size } else { size }
258
261
}
259
262
260
263
pub unsafe fn deallocate ( ptr : * mut u8 , _old_size : usize , align : usize ) {
0 commit comments