Skip to content

Commit 0e036eb

Browse files
authored
Merge pull request #55 from jonas-schievink/inline
Mark a few functions as inline
2 parents 157670a + 1075535 commit 0e036eb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/exti.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ pub fn line_is_triggered(reg: u32, line: u8) -> bool {
3434
}
3535

3636
impl ExtiExt for EXTI {
37+
// `port`, `line` and `edge` are almost always constants, so make sure they can be
38+
// constant-propagated by marking the function as `#[inline]`. This saves ~600 Bytes in some
39+
// simple apps (eg. the `pwr.rs` example).
40+
#[inline]
3741
fn listen(&self, syscfg: &mut SYSCFG, port: gpio::Port, line: u8, edge: TriggerEdge) {
3842
assert!(line <= 22);
3943
assert_ne!(line, 18);

src/rcc.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub struct Config {
100100
}
101101

102102
impl Default for Config {
103+
#[inline]
103104
fn default() -> Config {
104105
Config {
105106
mux: ClockSrc::MSI(MSIRange::default()),
@@ -111,26 +112,31 @@ impl Default for Config {
111112
}
112113

113114
impl Config {
115+
#[inline]
114116
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
115117
self.mux = mux;
116118
self
117119
}
118120

121+
#[inline]
119122
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
120123
self.ahb_pre = pre;
121124
self
122125
}
123126

127+
#[inline]
124128
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
125129
self.apb1_pre = pre;
126130
self
127131
}
128132

133+
#[inline]
129134
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
130135
self.apb2_pre = pre;
131136
self
132137
}
133138

139+
#[inline]
134140
pub fn hsi16() -> Config {
135141
Config {
136142
mux: ClockSrc::HSI16,
@@ -140,6 +146,7 @@ impl Config {
140146
}
141147
}
142148

149+
#[inline]
143150
pub fn msi(range: MSIRange) -> Config {
144151
Config {
145152
mux: ClockSrc::MSI(range),
@@ -149,6 +156,7 @@ impl Config {
149156
}
150157
}
151158

159+
#[inline]
152160
pub fn pll(pll_src: PLLSource, pll_mul: PLLMul, pll_div: PLLDiv) -> Config {
153161
Config {
154162
mux: ClockSrc::PLL(pll_src, pll_mul, pll_div),
@@ -158,6 +166,7 @@ impl Config {
158166
}
159167
}
160168

169+
#[inline]
161170
pub fn hse<T>(freq: T) -> Config
162171
where
163172
T: Into<Hertz>,
@@ -222,6 +231,10 @@ pub trait RccExt {
222231
}
223232

224233
impl RccExt for RCC {
234+
// `cfgr` is almost always a constant, so make sure it can be constant-propagated properly by
235+
// marking this function and all `Config` constructors and setters as `#[inline]`.
236+
// This saves ~900 Bytes for the `pwr.rs` example.
237+
#[inline]
225238
fn freeze(self, cfgr: Config) -> Rcc {
226239
let (sys_clk, sw_bits) = match cfgr.mux {
227240
ClockSrc::MSI(range) => {

0 commit comments

Comments
 (0)