Optimize line offset parsing in <SourceFile as Decodable>::decode
By inverting parsing loop, avoiding continually re-checking bytes_per_diff.
This commit is contained in:
parent
4e1927db3c
commit
2b14529a7c
1 changed files with 20 additions and 11 deletions
|
@ -1318,19 +1318,28 @@ impl<D: Decoder> Decodable<D> for SourceFile {
|
||||||
let mut line_start: BytePos = Decodable::decode(d);
|
let mut line_start: BytePos = Decodable::decode(d);
|
||||||
lines.push(line_start);
|
lines.push(line_start);
|
||||||
|
|
||||||
|
match bytes_per_diff {
|
||||||
|
1 => {
|
||||||
for _ in 1..num_lines {
|
for _ in 1..num_lines {
|
||||||
let diff = match bytes_per_diff {
|
line_start = line_start + BytePos(d.read_u8() as u32);
|
||||||
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lines
|
lines
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue