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

index, stacked_table: inline read_u32::<LittleEndian>()

There aren't many callers of ReadBytesExt::read_u32().
This commit is contained in:
Yuya Nishihara 2023-12-22 09:06:40 +09:00
parent 21c22be96e
commit 9de6273e10
2 changed files with 20 additions and 7 deletions

View file

@ -23,7 +23,6 @@ use std::io::Read;
use std::path::Path;
use std::sync::Arc;
use byteorder::{LittleEndian, ReadBytesExt};
use smallvec::SmallVec;
use thiserror::Error;
@ -216,7 +215,12 @@ impl ReadonlyIndexSegment {
change_id_length: usize,
) -> Result<Arc<ReadonlyIndexSegment>, ReadonlyIndexLoadError> {
let from_io_err = |err| ReadonlyIndexLoadError::from_io_err(&name, err);
let parent_filename_len = file.read_u32::<LittleEndian>().map_err(from_io_err)?;
let read_u32 = |file: &mut dyn Read| {
let mut buf = [0; 4];
file.read_exact(&mut buf).map_err(from_io_err)?;
Ok(u32::from_le_bytes(buf))
};
let parent_filename_len = read_u32(file)?;
let maybe_parent_file = if parent_filename_len > 0 {
let mut parent_filename_bytes = vec![0; parent_filename_len as usize];
file.read_exact(&mut parent_filename_bytes)
@ -253,11 +257,16 @@ impl ReadonlyIndexSegment {
change_id_length: usize,
) -> Result<Arc<ReadonlyIndexSegment>, ReadonlyIndexLoadError> {
let from_io_err = |err| ReadonlyIndexLoadError::from_io_err(&name, err);
let read_u32 = |file: &mut dyn Read| {
let mut buf = [0; 4];
file.read_exact(&mut buf).map_err(from_io_err)?;
Ok(u32::from_le_bytes(buf))
};
let num_parent_commits = parent_file
.as_ref()
.map_or(0, |segment| segment.as_composite().num_commits());
let num_local_commits = file.read_u32::<LittleEndian>().map_err(from_io_err)?;
let num_parent_overflow_entries = file.read_u32::<LittleEndian>().map_err(from_io_err)?;
let num_local_commits = read_u32(file)?;
let num_parent_overflow_entries = read_u32(file)?;
let mut data = vec![];
file.read_to_end(&mut data).map_err(from_io_err)?;
let commit_graph_entry_size = CommitGraphEntry::size(commit_id_length, change_id_length);

View file

@ -29,7 +29,6 @@ use std::path::PathBuf;
use std::sync::{Arc, RwLock};
use blake2::{Blake2b512, Digest};
use byteorder::{LittleEndian, ReadBytesExt};
use tempfile::NamedTempFile;
use thiserror::Error;
@ -74,7 +73,12 @@ impl ReadonlyTable {
name: String,
key_size: usize,
) -> TableStoreResult<Arc<ReadonlyTable>> {
let parent_filename_len = file.read_u32::<LittleEndian>()?;
let read_u32 = |file: &mut dyn Read| -> io::Result<u32> {
let mut buf = [0; 4];
file.read_exact(&mut buf)?;
Ok(u32::from_le_bytes(buf))
};
let parent_filename_len = read_u32(file)?;
let maybe_parent_file = if parent_filename_len > 0 {
let mut parent_filename_bytes = vec![0; parent_filename_len as usize];
file.read_exact(&mut parent_filename_bytes)?;
@ -84,7 +88,7 @@ impl ReadonlyTable {
} else {
None
};
let num_local_entries = file.read_u32::<LittleEndian>()? as usize;
let num_local_entries = read_u32(file)? as usize;
let index_size = num_local_entries * ReadonlyTableIndexEntry::size(key_size);
let mut data = vec![];
file.read_to_end(&mut data)?;