mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-13 22:28:26 +00:00
Make loading of cached assets closer in performance to integrated assets
Using BufReader makes sense for large files, but assets are never large enough to require buffering. It is significantly faster to load the file contents in one go, so let's do that instead. Closes #1753
This commit is contained in:
parent
fb1ab09e3e
commit
ccf4563573
@ -8,6 +8,8 @@
|
||||
|
||||
## Other
|
||||
|
||||
- Load cached assets as fast as integrated assets, see #1753 (@Enselic)
|
||||
|
||||
|
||||
## Syntaxes
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs::{self, File};
|
||||
use std::io::BufReader;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
||||
@ -298,15 +297,14 @@ fn asset_to_cache<T: serde::Serialize>(asset: &T, path: &Path, description: &str
|
||||
}
|
||||
|
||||
fn asset_from_cache<T: serde::de::DeserializeOwned>(path: &Path, description: &str) -> Result<T> {
|
||||
let asset_file = File::open(&path).chain_err(|| {
|
||||
let contents = fs::read(path).chain_err(|| {
|
||||
format!(
|
||||
"Could not load cached {} '{}'",
|
||||
description,
|
||||
path.to_string_lossy()
|
||||
)
|
||||
})?;
|
||||
from_reader(BufReader::new(asset_file))
|
||||
.chain_err(|| format!("Could not parse cached {}", description))
|
||||
from_reader(&contents[..]).chain_err(|| format!("Could not parse cached {}", description))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -316,7 +314,7 @@ mod tests {
|
||||
use std::ffi::OsStr;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::io::{BufReader, Write};
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::input::Input;
|
||||
|
Loading…
x
Reference in New Issue
Block a user