Skip to content

Commit 5f2c6b9

Browse files
committed
Use .extend(..) instead of push()-ing in loop
A bit less readable but more compact, and maybe faster? We'll see.
1 parent 2b14529 commit 5f2c6b9

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

compiler/rustc_span/src/lib.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -1319,24 +1319,18 @@ impl<D: Decoder> Decodable<D> for SourceFile {
13191319
lines.push(line_start);
13201320

13211321
match bytes_per_diff {
1322-
1 => {
1323-
for _ in 1..num_lines {
1324-
line_start = line_start + BytePos(d.read_u8() as u32);
1325-
lines.push(line_start);
1326-
}
1327-
}
1328-
2 => {
1329-
for _ in 1..num_lines {
1330-
line_start = line_start + BytePos(d.read_u16() as u32);
1331-
lines.push(line_start);
1332-
}
1333-
}
1334-
4 => {
1335-
for _ in 1..num_lines {
1336-
line_start = line_start + BytePos(d.read_u32());
1337-
lines.push(line_start);
1338-
}
1339-
}
1322+
1 => lines.extend((1..num_lines).map(|_| {
1323+
line_start = line_start + BytePos(d.read_u8() as u32);
1324+
line_start
1325+
})),
1326+
2 => lines.extend((1..num_lines).map(|_| {
1327+
line_start = line_start + BytePos(d.read_u16() as u32);
1328+
line_start
1329+
})),
1330+
4 => lines.extend((1..num_lines).map(|_| {
1331+
line_start = line_start + BytePos(d.read_u32());
1332+
line_start
1333+
})),
13401334
_ => unreachable!(),
13411335
}
13421336
}

0 commit comments

Comments
 (0)