Skip to content

Commit

Permalink
Use .extend(..) instead of push()-ing in loop
Browse files Browse the repository at this point in the history
A bit less readable but more compact, and maybe faster? We'll see.
  • Loading branch information
martingms committed Apr 13, 2022
1 parent 2b14529 commit 5f2c6b9
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,24 +1319,18 @@ impl<D: Decoder> Decodable<D> for SourceFile {
lines.push(line_start);

match bytes_per_diff {
1 => {
for _ in 1..num_lines {
line_start = line_start + BytePos(d.read_u8() as u32);
lines.push(line_start);
}
}
2 => {
for _ in 1..num_lines {
line_start = line_start + BytePos(d.read_u16() as u32);
lines.push(line_start);
}
}
4 => {
for _ in 1..num_lines {
line_start = line_start + BytePos(d.read_u32());
lines.push(line_start);
}
}
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

0 comments on commit 5f2c6b9

Please sign in to comment.