diff options
| author | Martin Gammelsæter <martin@mg.am> | 2022-04-13 08:44:20 +0200 |
|---|---|---|
| committer | Martin Gammelsæter <martin@mg.am> | 2022-04-13 08:44:20 +0200 |
| commit | 5f2c6b92d1cb2749872432448d42cd9cb05b0565 (patch) | |
| tree | bf464be68ba2700b3f5c13f8981f83d80156b16c | |
| parent | 2b14529a7cc106d5d808529cd14d71aa158c7789 (diff) | |
| download | rust-5f2c6b92d1cb2749872432448d42cd9cb05b0565.tar.gz rust-5f2c6b92d1cb2749872432448d42cd9cb05b0565.zip | |
Use .extend(..) instead of push()-ing in loop
A bit less readable but more compact, and maybe faster? We'll see.
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 68401d5ca7c..45b0e0c2dd1 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -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!(), } } |
