Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always inline simple BytePos and CharPos methods. #50407

Merged
merged 1 commit into from
May 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,13 +1150,17 @@ pub struct CharPos(pub usize);
// have been unsuccessful

impl Pos for BytePos {
#[inline(always)]
fn from_usize(n: usize) -> BytePos { BytePos(n as u32) }

#[inline(always)]
fn to_usize(&self) -> usize { let BytePos(n) = *self; n as usize }
}

impl Add for BytePos {
type Output = BytePos;

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

#[inline(always)]
fn sub(self, rhs: BytePos) -> BytePos {
BytePos((self.to_usize() - rhs.to_usize()) as u32)
}
Expand All @@ -1183,13 +1188,17 @@ impl Decodable for BytePos {
}

impl Pos for CharPos {
#[inline(always)]
fn from_usize(n: usize) -> CharPos { CharPos(n) }

#[inline(always)]
fn to_usize(&self) -> usize { let CharPos(n) = *self; n }
}

impl Add for CharPos {
type Output = CharPos;

#[inline(always)]
fn add(self, rhs: CharPos) -> CharPos {
CharPos(self.to_usize() + rhs.to_usize())
}
Expand All @@ -1198,6 +1207,7 @@ impl Add for CharPos {
impl Sub for CharPos {
type Output = CharPos;

#[inline(always)]
fn sub(self, rhs: CharPos) -> CharPos {
CharPos(self.to_usize() - rhs.to_usize())
}
Expand Down