patch: make BufReader preload its buffer

Signed-off-by: ClSlaid <cailue@bupt.edu.cn>
This commit is contained in:
ClSlaid 2023-10-28 23:25:30 +08:00
parent a575fe4934
commit f6a137cd43
No known key found for this signature in database
GPG Key ID: E0A5F564C51C056E

View File

@ -1,7 +1,7 @@
use std::{ use std::{
collections::HashSet, collections::HashSet,
fs::File, fs::File,
io::{BufReader, Read, Seek}, io::{BufRead, BufReader, Read, Seek},
os::unix::prelude::PermissionsExt, os::unix::prelude::PermissionsExt,
path::PathBuf, path::PathBuf,
sync::atomic::{AtomicU64, Ordering}, sync::atomic::{AtomicU64, Ordering},
@ -175,7 +175,11 @@ impl LocalFile {
path: self.path.clone(), path: self.path.clone(),
err: e, err: e,
})?; })?;
let reader = BufReader::with_capacity(BLOCK_SIZE as usize, handle); let mut reader = BufReader::with_capacity(BLOCK_SIZE as usize * 2, handle);
reader.fill_buf().map_err(|e| CliprdrError::FileError {
path: self.path.clone(),
err: e,
})?;
self.handle = Some(reader); self.handle = Some(reader);
}; };
Ok(()) Ok(())