Skip to content

Commit 429bc8d

Browse files
committed
Inline all methods on abi::Size
This save 3 seconds on the test program.
1 parent 63ab0cb commit 429bc8d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/librustc_target/abi/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,13 @@ pub struct Size {
229229
impl Size {
230230
pub const ZERO: Size = Self::from_bytes(0);
231231

232+
#[inline]
232233
pub fn from_bits(bits: u64) -> Size {
233234
// Avoid potential overflow from `bits + 7`.
234235
Size::from_bytes(bits / 8 + ((bits % 8) + 7) / 8)
235236
}
236237

238+
#[inline]
237239
pub const fn from_bytes(bytes: u64) -> Size {
238240
Size {
239241
raw: bytes
@@ -245,22 +247,26 @@ impl Size {
245247
self.raw
246248
}
247249

250+
#[inline]
248251
pub fn bits(self) -> u64 {
249252
self.bytes().checked_mul(8).unwrap_or_else(|| {
250253
panic!("Size::bits: {} bytes in bits doesn't fit in u64", self.bytes())
251254
})
252255
}
253256

257+
#[inline]
254258
pub fn abi_align(self, align: Align) -> Size {
255259
let mask = align.abi() - 1;
256260
Size::from_bytes((self.bytes() + mask) & !mask)
257261
}
258262

263+
#[inline]
259264
pub fn is_abi_aligned(self, align: Align) -> bool {
260265
let mask = align.abi() - 1;
261266
self.bytes() & mask == 0
262267
}
263268

269+
#[inline]
264270
pub fn checked_add<C: HasDataLayout>(self, offset: Size, cx: C) -> Option<Size> {
265271
let dl = cx.data_layout();
266272

@@ -273,6 +279,7 @@ impl Size {
273279
}
274280
}
275281

282+
#[inline]
276283
pub fn checked_mul<C: HasDataLayout>(self, count: u64, cx: C) -> Option<Size> {
277284
let dl = cx.data_layout();
278285

@@ -290,6 +297,7 @@ impl Size {
290297

291298
impl Add for Size {
292299
type Output = Size;
300+
#[inline]
293301
fn add(self, other: Size) -> Size {
294302
Size::from_bytes(self.bytes().checked_add(other.bytes()).unwrap_or_else(|| {
295303
panic!("Size::add: {} + {} doesn't fit in u64", self.bytes(), other.bytes())
@@ -299,6 +307,7 @@ impl Add for Size {
299307

300308
impl Sub for Size {
301309
type Output = Size;
310+
#[inline]
302311
fn sub(self, other: Size) -> Size {
303312
Size::from_bytes(self.bytes().checked_sub(other.bytes()).unwrap_or_else(|| {
304313
panic!("Size::sub: {} - {} would result in negative size", self.bytes(), other.bytes())
@@ -308,13 +317,15 @@ impl Sub for Size {
308317

309318
impl Mul<Size> for u64 {
310319
type Output = Size;
320+
#[inline]
311321
fn mul(self, size: Size) -> Size {
312322
size * self
313323
}
314324
}
315325

316326
impl Mul<u64> for Size {
317327
type Output = Size;
328+
#[inline]
318329
fn mul(self, count: u64) -> Size {
319330
match self.bytes().checked_mul(count) {
320331
Some(bytes) => Size::from_bytes(bytes),
@@ -326,6 +337,7 @@ impl Mul<u64> for Size {
326337
}
327338

328339
impl AddAssign for Size {
340+
#[inline]
329341
fn add_assign(&mut self, other: Size) {
330342
*self = *self + other;
331343
}

0 commit comments

Comments
 (0)