Skip to content

Commit c254497

Browse files
committed
Reduce indentation by using let-else-pattern
1 parent f0eeb77 commit c254497

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/tlsf.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,16 @@ impl Heap {
7878
assert!(!heap.initialized);
7979
let block: NonNull<[u8]> =
8080
NonNull::slice_from_raw_parts(NonNull::new_unchecked(start_addr as *mut u8), size);
81-
if let Some(actual_size) = heap.tlsf.insert_free_block_ptr(block) {
82-
let block: NonNull<[u8]> = NonNull::slice_from_raw_parts(
83-
NonNull::new_unchecked(start_addr as *mut u8),
84-
actual_size.get(),
85-
);
86-
heap.initialized = true;
87-
heap.raw_block = Some(block);
88-
heap.raw_block_size = size;
89-
}
90-
if !heap.initialized {
81+
let Some(actual_size) = heap.tlsf.insert_free_block_ptr(block) else {
9182
panic!("Allocation too small for heap");
92-
}
83+
};
84+
let block: NonNull<[u8]> = NonNull::slice_from_raw_parts(
85+
NonNull::new_unchecked(start_addr as *mut u8),
86+
actual_size.get(),
87+
);
88+
heap.initialized = true;
89+
heap.raw_block = Some(block);
90+
heap.raw_block_size = size;
9391
});
9492
}
9593

0 commit comments

Comments
 (0)