on master help sign in
Make loading of cached assets closer in performance to integrated assets
ccf4563Martin Nordholts
CHANGELOG.md+2
@@ -8,6 +8,8 @@
8
8
9## Other
9## Other
10
10
11+- Load cached assets as fast as integrated assets, see #1753 (@Enselic)
12+
11
13
12## Syntaxes
14## Syntaxes
13
15
src/assets.rs+4−6
@@ -1,7 +1,6 @@
1use std::collections::BTreeMap;
1use std::collections::BTreeMap;
2use std::ffi::OsStr;
2use std::ffi::OsStr;
3−use std::fs::{self, File};
3+use std::fs;
4−use std::io::BufReader;
5use std::path::Path;
4use std::path::Path;
6
5
7use syntect::dumps::{dump_to_file, from_binary, from_reader};
6use 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
298}
297}
299
298
300fn asset_from_cache<T: serde::de::DeserializeOwned>(path: &Path, description: &str) -> Result<T> {
299fn asset_from_cache<T: serde::de::DeserializeOwned>(path: &Path, description: &str) -> Result<T> {
301− let asset_file = File::open(&path).chain_err(|| {
300+ let contents = fs::read(path).chain_err(|| {
302 format!(
301 format!(
303 "Could not load cached {} '{}'",
302 "Could not load cached {} '{}'",
304 description,
303 description,
305 path.to_string_lossy()
304 path.to_string_lossy()
306 )
305 )
307 })?;
306 })?;
308− from_reader(BufReader::new(asset_file))
309− .chain_err(|| format!("Could not parse cached {}", description))
307+ from_reader(&contents[..]).chain_err(|| format!("Could not parse cached {}", description))
310}
308}
311
309
312#[cfg(test)]
310#[cfg(test)]
@@ -316,7 +314,7 @@ mod tests {
316 use std::ffi::OsStr;
314 use std::ffi::OsStr;
317
315
318 use std::fs::File;
316 use std::fs::File;
319− use std::io::Write;
317+ use std::io::{BufReader, Write};
320 use tempfile::TempDir;
318 use tempfile::TempDir;
321
319
322 use crate::input::Input;
320 use crate::input::Input;