Skip to content

Optimize <SourceFile as Decodable>::decode #95981

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

Merged
merged 2 commits into from
Apr 14, 2022
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
25 changes: 14 additions & 11 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,17 +1318,20 @@ impl<D: Decoder> Decodable<D> for SourceFile {
let mut line_start: BytePos = Decodable::decode(d);
lines.push(line_start);

for _ in 1..num_lines {
let diff = match bytes_per_diff {
1 => d.read_u8() as u32,
2 => d.read_u16() as u32,
4 => d.read_u32(),
_ => unreachable!(),
};

line_start = line_start + BytePos(diff);

lines.push(line_start);
match bytes_per_diff {
1 => lines.extend((1..num_lines).map(|_| {
line_start = line_start + BytePos(d.read_u8() as u32);
line_start
})),
2 => lines.extend((1..num_lines).map(|_| {
line_start = line_start + BytePos(d.read_u16() as u32);
line_start
})),
4 => lines.extend((1..num_lines).map(|_| {
line_start = line_start + BytePos(d.read_u32());
line_start
})),
_ => unreachable!(),
}
}

Expand Down