[thin_check (rust)] Optimise SyncIoEngine
*_many no longer get/put for each block
This commit is contained in:
@@ -88,7 +88,6 @@ impl<'a> FileGuard<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Deref for FileGuard<'a> {
|
impl<'a> Deref for FileGuard<'a> {
|
||||||
// FIXME: do we need this? it's not in DerefMut
|
|
||||||
type Target = File;
|
type Target = File;
|
||||||
|
|
||||||
fn deref(&self) -> &File {
|
fn deref(&self) -> &File {
|
||||||
@@ -148,6 +147,19 @@ impl SyncIoEngine {
|
|||||||
files.push(f);
|
files.push(f);
|
||||||
self.cvar.notify_one();
|
self.cvar.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_(input: &mut File, loc: u64) -> Result<Block> {
|
||||||
|
let b = Block::new(loc);
|
||||||
|
input.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
|
||||||
|
input.read_exact(b.get_data())?;
|
||||||
|
Ok(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_(output: &mut File, b: &Block) -> Result<()> {
|
||||||
|
output.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
|
||||||
|
output.write_all(&b.get_data())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IoEngine for SyncIoEngine {
|
impl IoEngine for SyncIoEngine {
|
||||||
@@ -156,34 +168,27 @@ impl IoEngine for SyncIoEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read(&self, loc: u64) -> Result<Block> {
|
fn read(&self, loc: u64) -> Result<Block> {
|
||||||
let b = Block::new(loc);
|
SyncIoEngine::read_(&mut self.get(), loc)
|
||||||
let mut input = self.get();
|
|
||||||
|
|
||||||
input.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
|
|
||||||
input.read_exact(b.get_data())?;
|
|
||||||
Ok(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: *_many are getting and putting the input many times
|
|
||||||
fn read_many(&self, blocks: &[u64]) -> Result<Vec<Result<Block>>> {
|
fn read_many(&self, blocks: &[u64]) -> Result<Vec<Result<Block>>> {
|
||||||
|
let mut input = self.get();
|
||||||
let mut bs = Vec::new();
|
let mut bs = Vec::new();
|
||||||
for b in blocks {
|
for b in blocks {
|
||||||
bs.push(self.read(*b));
|
bs.push(SyncIoEngine::read_(&mut input, *b));
|
||||||
}
|
}
|
||||||
Ok(bs)
|
Ok(bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&self, b: &Block) -> Result<()> {
|
fn write(&self, b: &Block) -> Result<()> {
|
||||||
let mut input = self.get();
|
SyncIoEngine::write_(&mut self.get(), b)
|
||||||
input.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
|
|
||||||
input.write_all(&b.get_data())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_many(&self, blocks: &[Block]) -> Result<Vec<Result<()>>> {
|
fn write_many(&self, blocks: &[Block]) -> Result<Vec<Result<()>>> {
|
||||||
|
let mut output = self.get();
|
||||||
let mut bs = Vec::new();
|
let mut bs = Vec::new();
|
||||||
for b in blocks {
|
for b in blocks {
|
||||||
bs.push(self.write(b));
|
bs.push(SyncIoEngine::write_(&mut output, b));
|
||||||
}
|
}
|
||||||
Ok(bs)
|
Ok(bs)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user