1
Fork 0

Use .extend(..) instead of push()-ing in loop

A bit less readable but more compact, and maybe faster? We'll see.
This commit is contained in:
Martin Gammelsæter 2022-04-13 08:44:20 +02:00
parent 2b14529a7c
commit 5f2c6b92d1

View file

@ -1319,24 +1319,18 @@ impl<D: Decoder> Decodable<D> for SourceFile {
lines.push(line_start); lines.push(line_start);
match bytes_per_diff { match bytes_per_diff {
1 => { 1 => lines.extend((1..num_lines).map(|_| {
for _ in 1..num_lines {
line_start = line_start + BytePos(d.read_u8() as u32); line_start = line_start + BytePos(d.read_u8() as u32);
lines.push(line_start); line_start
} })),
} 2 => lines.extend((1..num_lines).map(|_| {
2 => {
for _ in 1..num_lines {
line_start = line_start + BytePos(d.read_u16() as u32); line_start = line_start + BytePos(d.read_u16() as u32);
lines.push(line_start); line_start
} })),
} 4 => lines.extend((1..num_lines).map(|_| {
4 => {
for _ in 1..num_lines {
line_start = line_start + BytePos(d.read_u32()); line_start = line_start + BytePos(d.read_u32());
lines.push(line_start); line_start
} })),
}
_ => unreachable!(), _ => unreachable!(),
} }
} }