@@ -182,9 +182,15 @@ mod imp {
182
182
183
183
#[ inline]
184
184
pub unsafe fn reallocate_inplace ( ptr : * mut u8 , size : uint , align : uint ,
185
- _old_size : uint ) -> bool {
185
+ old_size : uint ) -> bool {
186
186
let flags = align_to_flags ( align) ;
187
- je_xallocx ( ptr as * mut c_void , size as size_t , 0 , flags) == size as size_t
187
+ let new_size = je_xallocx ( ptr as * mut c_void , size as size_t , 0 , flags) as uint ;
188
+ // checking for failure to shrink is tricky
189
+ if size < old_size {
190
+ usable_size ( size, align) == new_size as uint
191
+ } else {
192
+ new_size >= size
193
+ }
188
194
}
189
195
190
196
#[ inline]
@@ -250,9 +256,9 @@ mod imp {
250
256
}
251
257
252
258
#[ inline]
253
- pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , _size : uint , _align : uint ,
254
- _old_size : uint ) -> bool {
255
- false
259
+ pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , size : uint , _align : uint ,
260
+ old_size : uint ) -> bool {
261
+ size == old_size
256
262
}
257
263
258
264
#[ inline]
@@ -312,9 +318,9 @@ mod imp {
312
318
}
313
319
314
320
#[ inline]
315
- pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , _size : uint , _align : uint ,
316
- _old_size : uint ) -> bool {
317
- false
321
+ pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , size : uint , _align : uint ,
322
+ old_size : uint ) -> bool {
323
+ size == old_size
318
324
}
319
325
320
326
#[ inline]
@@ -335,10 +341,21 @@ mod imp {
335
341
}
336
342
337
343
#[ cfg( test) ]
338
- mod bench {
344
+ mod test {
339
345
extern crate test;
340
346
use self :: test:: Bencher ;
341
347
348
+ #[ test]
349
+ fn basic_reallocate_inplace_noop ( ) {
350
+ unsafe {
351
+ let size = 4000 ;
352
+ let ptr = heap:: allocate ( size, 8 ) ;
353
+ let ret = heap:: reallocate_inplace ( ptr, size, 8 , size) ;
354
+ heap:: deallocate ( ptr, size, 8 ) ;
355
+ assert ! ( ret) ;
356
+ }
357
+ }
358
+
342
359
#[ bench]
343
360
fn alloc_owned_small ( b : & mut Bencher ) {
344
361
b. iter ( || {
0 commit comments