ok/jj
1
0
Fork 0
forked from mirrors/jj

index, stacked_table: simply extend Vec<u8> to not use .write_all()

I'm going to remove use of .write_u32() there. It's not super important, but
fewer .unwrap()s, the code looks slightly better.
This commit is contained in:
Yuya Nishihara 2023-12-18 18:11:43 +09:00
parent fb06e89649
commit 392539fa29
2 changed files with 7 additions and 7 deletions

View file

@ -174,7 +174,7 @@ impl MutableIndexSegment {
if let Some(parent_file) = &self.parent_file {
buf.write_u32::<LittleEndian>(parent_file.name().len() as u32)
.unwrap();
buf.write_all(parent_file.name().as_bytes()).unwrap();
buf.extend_from_slice(parent_file.name().as_bytes());
} else {
buf.write_u32::<LittleEndian>(0).unwrap();
}
@ -212,14 +212,14 @@ impl MutableIndexSegment {
buf.write_u32::<LittleEndian>(parent_overflow_pos).unwrap();
assert_eq!(entry.change_id.as_bytes().len(), self.change_id_length);
buf.write_all(entry.change_id.as_bytes()).unwrap();
buf.extend_from_slice(entry.change_id.as_bytes());
assert_eq!(entry.commit_id.as_bytes().len(), self.commit_id_length);
buf.write_all(entry.commit_id.as_bytes()).unwrap();
buf.extend_from_slice(entry.commit_id.as_bytes());
}
for (commit_id, pos) in &self.lookup {
buf.write_all(commit_id.as_bytes()).unwrap();
buf.extend_from_slice(commit_id.as_bytes());
buf.write_u32::<LittleEndian>(pos.0).unwrap();
}

View file

@ -258,7 +258,7 @@ impl MutableTable {
if let Some(parent_file) = &self.parent_file {
buf.write_u32::<LittleEndian>(parent_file.name.len() as u32)
.unwrap();
buf.write_all(parent_file.name.as_bytes()).unwrap();
buf.extend_from_slice(parent_file.name.as_bytes());
} else {
buf.write_u32::<LittleEndian>(0).unwrap();
}
@ -268,12 +268,12 @@ impl MutableTable {
let mut value_offset = 0;
for (key, value) in &self.entries {
buf.write_all(key).unwrap();
buf.extend_from_slice(key);
buf.write_u32::<LittleEndian>(value_offset).unwrap();
value_offset += value.len() as u32;
}
for value in self.entries.values() {
buf.write_all(value).unwrap();
buf.extend_from_slice(value);
}
buf
}