fix alignment
This commit is contained in:
parent
bd71d11a8f
commit
2628f3cc8f
34 changed files with 458 additions and 473 deletions
|
@ -530,51 +530,51 @@ impl Encodable for FileMap {
|
|||
s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s))?;
|
||||
s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s))?;
|
||||
s.emit_struct_field("lines", 3, |s| {
|
||||
let lines = self.lines.borrow();
|
||||
// store the length
|
||||
s.emit_u32(lines.len() as u32)?;
|
||||
let lines = self.lines.borrow();
|
||||
// store the length
|
||||
s.emit_u32(lines.len() as u32)?;
|
||||
|
||||
if !lines.is_empty() {
|
||||
// In order to preserve some space, we exploit the fact that
|
||||
// the lines list is sorted and individual lines are
|
||||
// probably not that long. Because of that we can store lines
|
||||
// as a difference list, using as little space as possible
|
||||
// for the differences.
|
||||
let max_line_length = if lines.len() == 1 {
|
||||
0
|
||||
} else {
|
||||
lines.windows(2)
|
||||
.map(|w| w[1] - w[0])
|
||||
.map(|bp| bp.to_usize())
|
||||
.max()
|
||||
.unwrap()
|
||||
};
|
||||
if !lines.is_empty() {
|
||||
// In order to preserve some space, we exploit the fact that
|
||||
// the lines list is sorted and individual lines are
|
||||
// probably not that long. Because of that we can store lines
|
||||
// as a difference list, using as little space as possible
|
||||
// for the differences.
|
||||
let max_line_length = if lines.len() == 1 {
|
||||
0
|
||||
} else {
|
||||
lines.windows(2)
|
||||
.map(|w| w[1] - w[0])
|
||||
.map(|bp| bp.to_usize())
|
||||
.max()
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let bytes_per_diff: u8 = match max_line_length {
|
||||
0 ... 0xFF => 1,
|
||||
0x100 ... 0xFFFF => 2,
|
||||
_ => 4
|
||||
};
|
||||
let bytes_per_diff: u8 = match max_line_length {
|
||||
0 ... 0xFF => 1,
|
||||
0x100 ... 0xFFFF => 2,
|
||||
_ => 4
|
||||
};
|
||||
|
||||
// Encode the number of bytes used per diff.
|
||||
bytes_per_diff.encode(s)?;
|
||||
// Encode the number of bytes used per diff.
|
||||
bytes_per_diff.encode(s)?;
|
||||
|
||||
// Encode the first element.
|
||||
lines[0].encode(s)?;
|
||||
// Encode the first element.
|
||||
lines[0].encode(s)?;
|
||||
|
||||
let diff_iter = (&lines[..]).windows(2)
|
||||
.map(|w| (w[1] - w[0]));
|
||||
let diff_iter = (&lines[..]).windows(2)
|
||||
.map(|w| (w[1] - w[0]));
|
||||
|
||||
match bytes_per_diff {
|
||||
1 => for diff in diff_iter { (diff.0 as u8).encode(s)? },
|
||||
2 => for diff in diff_iter { (diff.0 as u16).encode(s)? },
|
||||
4 => for diff in diff_iter { diff.0.encode(s)? },
|
||||
_ => unreachable!()
|
||||
}
|
||||
match bytes_per_diff {
|
||||
1 => for diff in diff_iter { (diff.0 as u8).encode(s)? },
|
||||
2 => for diff in diff_iter { (diff.0 as u16).encode(s)? },
|
||||
4 => for diff in diff_iter { diff.0.encode(s)? },
|
||||
_ => unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(())
|
||||
})?;
|
||||
s.emit_struct_field("multibyte_chars", 4, |s| {
|
||||
(*self.multibyte_chars.borrow()).encode(s)
|
||||
})
|
||||
|
@ -590,33 +590,33 @@ impl Decodable for FileMap {
|
|||
let start_pos: BytePos = d.read_struct_field("start_pos", 1, |d| Decodable::decode(d))?;
|
||||
let end_pos: BytePos = d.read_struct_field("end_pos", 2, |d| Decodable::decode(d))?;
|
||||
let lines: Vec<BytePos> = d.read_struct_field("lines", 3, |d| {
|
||||
let num_lines: u32 = Decodable::decode(d)?;
|
||||
let mut lines = Vec::with_capacity(num_lines as usize);
|
||||
let num_lines: u32 = Decodable::decode(d)?;
|
||||
let mut lines = Vec::with_capacity(num_lines as usize);
|
||||
|
||||
if num_lines > 0 {
|
||||
// Read the number of bytes used per diff.
|
||||
let bytes_per_diff: u8 = Decodable::decode(d)?;
|
||||
if num_lines > 0 {
|
||||
// Read the number of bytes used per diff.
|
||||
let bytes_per_diff: u8 = Decodable::decode(d)?;
|
||||
|
||||
// Read the first element.
|
||||
let mut line_start: BytePos = Decodable::decode(d)?;
|
||||
lines.push(line_start);
|
||||
|
||||
for _ in 1..num_lines {
|
||||
let diff = match bytes_per_diff {
|
||||
1 => d.read_u8()? as u32,
|
||||
2 => d.read_u16()? as u32,
|
||||
4 => d.read_u32()?,
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
line_start = line_start + BytePos(diff);
|
||||
|
||||
// Read the first element.
|
||||
let mut line_start: BytePos = Decodable::decode(d)?;
|
||||
lines.push(line_start);
|
||||
|
||||
for _ in 1..num_lines {
|
||||
let diff = match bytes_per_diff {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(lines)
|
||||
})?;
|
||||
Ok(lines)
|
||||
})?;
|
||||
let multibyte_chars: Vec<MultiByteChar> =
|
||||
d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?;
|
||||
Ok(FileMap {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue