Skip to content

Commit e740b97

Browse files
committed
Always inline simple BytePos and CharPos methods.
Because they are (a) trivial, and (b) super hot. This change speeds up most rustc-benchmarks, the best by 5%.
1 parent f76f6fb commit e740b97

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libsyntax_pos/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1150,13 +1150,17 @@ pub struct CharPos(pub usize);
11501150
// have been unsuccessful
11511151

11521152
impl Pos for BytePos {
1153+
#[inline(always)]
11531154
fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }
1155+
1156+
#[inline(always)]
11541157
fn to_usize(&self) -> usize { let BytePos(n) = *self; n as usize }
11551158
}
11561159

11571160
impl Add for BytePos {
11581161
type Output = BytePos;
11591162

1163+
#[inline(always)]
11601164
fn add(self, rhs: BytePos) -> BytePos {
11611165
BytePos((self.to_usize() + rhs.to_usize()) as u32)
11621166
}
@@ -1165,6 +1169,7 @@ impl Add for BytePos {
11651169
impl Sub for BytePos {
11661170
type Output = BytePos;
11671171

1172+
#[inline(always)]
11681173
fn sub(self, rhs: BytePos) -> BytePos {
11691174
BytePos((self.to_usize() - rhs.to_usize()) as u32)
11701175
}
@@ -1183,13 +1188,17 @@ impl Decodable for BytePos {
11831188
}
11841189

11851190
impl Pos for CharPos {
1191+
#[inline(always)]
11861192
fn from_usize(n: usize) -> CharPos { CharPos(n) }
1193+
1194+
#[inline(always)]
11871195
fn to_usize(&self) -> usize { let CharPos(n) = *self; n }
11881196
}
11891197

11901198
impl Add for CharPos {
11911199
type Output = CharPos;
11921200

1201+
#[inline(always)]
11931202
fn add(self, rhs: CharPos) -> CharPos {
11941203
CharPos(self.to_usize() + rhs.to_usize())
11951204
}
@@ -1198,6 +1207,7 @@ impl Add for CharPos {
11981207
impl Sub for CharPos {
11991208
type Output = CharPos;
12001209

1210+
#[inline(always)]
12011211
fn sub(self, rhs: CharPos) -> CharPos {
12021212
CharPos(self.to_usize() - rhs.to_usize())
12031213
}

0 commit comments

Comments
 (0)