Skip to content

Commit 2a12a12

Browse files
committed
fmt
1 parent da60035 commit 2a12a12

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

examples/global_alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
extern crate alloc;
66

7-
use core::panic::PanicInfo;
8-
use core::alloc::Layout;
97
use alloc::vec::Vec;
108
use alloc_cortex_m::CortexMHeap;
9+
use core::alloc::Layout;
10+
use core::panic::PanicInfo;
1111
use cortex_m_rt::entry;
1212

1313
#[global_allocator]

src/lib.rs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
99
#![no_std]
1010

11-
use core::cell::RefCell;
1211
use core::alloc::{GlobalAlloc, Layout};
12+
use core::cell::RefCell;
1313
use core::ptr::NonNull;
1414

1515
use cortex_m::interrupt::Mutex;
@@ -55,48 +55,39 @@ impl CortexMHeap {
5555
/// - `size > 0`
5656
pub unsafe fn init(&self, start_addr: usize, size: usize) {
5757
cortex_m::interrupt::free(|cs| {
58-
self.heap
59-
.borrow(cs)
60-
.borrow_mut()
61-
.init(start_addr, size);
58+
self.heap.borrow(cs).borrow_mut().init(start_addr, size);
6259
});
6360
}
6461

6562
/// Returns an estimate of the amount of bytes in use.
6663
pub fn used(&self) -> usize {
67-
cortex_m::interrupt::free(|cs| {
68-
self.heap
69-
.borrow(cs)
70-
.borrow_mut()
71-
.used()
72-
})
64+
cortex_m::interrupt::free(|cs| self.heap.borrow(cs).borrow_mut().used())
7365
}
7466

7567
/// Returns an estimate of the amount of bytes available.
7668
pub fn free(&self) -> usize {
77-
cortex_m::interrupt::free(|cs| {
78-
self.heap
79-
.borrow(cs)
80-
.borrow_mut()
81-
.free()
82-
})
69+
cortex_m::interrupt::free(|cs| self.heap.borrow(cs).borrow_mut().free())
8370
}
8471
}
8572

8673
unsafe impl GlobalAlloc for CortexMHeap {
8774
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
88-
cortex_m::interrupt::free(|cs| self.heap
89-
.borrow(cs)
90-
.borrow_mut()
91-
.allocate_first_fit(layout)
92-
.ok()
93-
.map_or(0 as *mut u8, |allocation| allocation.as_ptr()))
75+
cortex_m::interrupt::free(|cs| {
76+
self.heap
77+
.borrow(cs)
78+
.borrow_mut()
79+
.allocate_first_fit(layout)
80+
.ok()
81+
.map_or(0 as *mut u8, |allocation| allocation.as_ptr())
82+
})
9483
}
9584

9685
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
97-
cortex_m::interrupt::free(|cs| self.heap
98-
.borrow(cs)
99-
.borrow_mut()
100-
.deallocate(NonNull::new_unchecked(ptr), layout));
86+
cortex_m::interrupt::free(|cs| {
87+
self.heap
88+
.borrow(cs)
89+
.borrow_mut()
90+
.deallocate(NonNull::new_unchecked(ptr), layout)
91+
});
10192
}
10293
}

0 commit comments

Comments
 (0)