diff options
| author | Wesley Wiser <wwiser@gmail.com> | 2018-06-27 19:34:42 -0400 |
|---|---|---|
| committer | Wesley Wiser <wwiser@gmail.com> | 2018-06-27 19:34:42 -0400 |
| commit | 429bc8d0cc72eb30541886610d5fb9e8969244fa (patch) | |
| tree | 8efd49b55a7e91a1b3a528f78e9b3b9b8b36122b | |
| parent | 63ab0cba7d36c4768bc64a27382fc56ca3a390ce (diff) | |
| download | rust-429bc8d0cc72eb30541886610d5fb9e8969244fa.tar.gz rust-429bc8d0cc72eb30541886610d5fb9e8969244fa.zip | |
Inline all methods on `abi::Size`
This save 3 seconds on the test program.
| -rw-r--r-- | src/librustc_target/abi/mod.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 4deac0444b9..57622692426 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -229,11 +229,13 @@ pub struct Size { impl Size { pub const ZERO: Size = Self::from_bytes(0); + #[inline] pub fn from_bits(bits: u64) -> Size { // Avoid potential overflow from `bits + 7`. Size::from_bytes(bits / 8 + ((bits % 8) + 7) / 8) } + #[inline] pub const fn from_bytes(bytes: u64) -> Size { Size { raw: bytes @@ -245,22 +247,26 @@ impl Size { self.raw } + #[inline] pub fn bits(self) -> u64 { self.bytes().checked_mul(8).unwrap_or_else(|| { panic!("Size::bits: {} bytes in bits doesn't fit in u64", self.bytes()) }) } + #[inline] pub fn abi_align(self, align: Align) -> Size { let mask = align.abi() - 1; Size::from_bytes((self.bytes() + mask) & !mask) } + #[inline] pub fn is_abi_aligned(self, align: Align) -> bool { let mask = align.abi() - 1; self.bytes() & mask == 0 } + #[inline] pub fn checked_add<C: HasDataLayout>(self, offset: Size, cx: C) -> Option<Size> { let dl = cx.data_layout(); @@ -273,6 +279,7 @@ impl Size { } } + #[inline] pub fn checked_mul<C: HasDataLayout>(self, count: u64, cx: C) -> Option<Size> { let dl = cx.data_layout(); @@ -290,6 +297,7 @@ impl Size { impl Add for Size { type Output = Size; + #[inline] fn add(self, other: Size) -> Size { Size::from_bytes(self.bytes().checked_add(other.bytes()).unwrap_or_else(|| { panic!("Size::add: {} + {} doesn't fit in u64", self.bytes(), other.bytes()) @@ -299,6 +307,7 @@ impl Add for Size { impl Sub for Size { type Output = Size; + #[inline] fn sub(self, other: Size) -> Size { Size::from_bytes(self.bytes().checked_sub(other.bytes()).unwrap_or_else(|| { panic!("Size::sub: {} - {} would result in negative size", self.bytes(), other.bytes()) @@ -308,6 +317,7 @@ impl Sub for Size { impl Mul<Size> for u64 { type Output = Size; + #[inline] fn mul(self, size: Size) -> Size { size * self } @@ -315,6 +325,7 @@ impl Mul<Size> for u64 { impl Mul<u64> for Size { type Output = Size; + #[inline] fn mul(self, count: u64) -> Size { match self.bytes().checked_mul(count) { Some(bytes) => Size::from_bytes(bytes), @@ -326,6 +337,7 @@ impl Mul<u64> for Size { } impl AddAssign for Size { + #[inline] fn add_assign(&mut self, other: Size) { *self = *self + other; } |
