@@ -76,37 +76,25 @@ impl Heap {
7676 critical_section:: with ( |cs| {
7777 let mut heap = self . heap . borrow_ref_mut ( cs) ;
7878 assert ! ( !heap. initialized) ;
79- // Work around https://github.com/yvt/rlsf/pull/21 by aligning block before passing
80- // it to `Tlsf::insert_free_block_ptr`.
81- if let Some ( ( aligned_start_addr, usable_size) ) = Self :: align ( start_addr, size) {
79+ let block: NonNull < [ u8 ] > = NonNull :: slice_from_raw_parts (
80+ NonNull :: new_unchecked ( start_addr as * mut u8 ) ,
81+ size,
82+ ) ;
83+ if let Some ( actual_size) = heap. tlsf . insert_free_block_ptr ( block) {
8284 let block: NonNull < [ u8 ] > = NonNull :: slice_from_raw_parts (
83- NonNull :: new_unchecked ( aligned_start_addr as * mut u8 ) ,
84- usable_size ,
85+ NonNull :: new_unchecked ( start_addr as * mut u8 ) ,
86+ actual_size . get ( ) ,
8587 ) ;
86- if heap. tlsf . insert_free_block_ptr ( block) . is_some ( ) {
87- heap. initialized = true ;
88- heap. raw_block = Some ( block) ;
89- heap. raw_block_size = size;
90- }
88+ heap. initialized = true ;
89+ heap. raw_block = Some ( block) ;
90+ heap. raw_block_size = size;
9191 }
9292 if !heap. initialized {
9393 panic ! ( "Allocation too small for heap" ) ;
9494 }
9595 } ) ;
9696 }
9797
98- /// Align `start_addr` to `rlsf::GRANULARITY` and make
99- /// `size` a multiple of `2*rlsf::GRANULARITY`.
100- fn align ( start_addr : usize , size : usize ) -> Option < ( usize , usize ) > {
101- let align_offset: usize = ( start_addr as * const u8 ) . align_offset ( rlsf:: GRANULARITY ) ;
102- if align_offset >= size {
103- return None ;
104- }
105- let reduced_size: usize = size - align_offset;
106- let usable_size: usize = reduced_size - ( reduced_size % ( rlsf:: GRANULARITY * 2 ) ) ;
107- Some ( ( start_addr + align_offset, usable_size) )
108- }
109-
11098 fn alloc ( & self , layout : Layout ) -> Option < NonNull < u8 > > {
11199 critical_section:: with ( |cs| self . heap . borrow_ref_mut ( cs) . tlsf . allocate ( layout) )
112100 }
0 commit comments