You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SerializedSyntaxSet: Load cache data early; only parse lazily
The slow part is parsing, so we can load the data from the file during startup
without a big performance hit. The benefit of loading the data during startup is
that we can better detect when the cache is incomplete, and fallback to data
from the binary.
In particular, this change makes the following scenario fallback to syntaxes.bin
from the binary during startup (same behavior as current bat), rather than
panicing when we try to lazily load syntaxes.bin that does not exist:
bat cache --build --source assets
rm ~/.cache/bat/syntaxes.bin
bat any-file > /tmp/out.txt
/// The data comes from a user-generated cache file.
311
-
FromFile(PathBuf),
311
+
FromFile(Vec<u8>),
312
312
313
313
/// The data to use is embedded into the bat binary.
314
314
FromBinary(&'static[u8]),
@@ -320,8 +320,8 @@ impl SerializedSyntaxSet {
320
320
SerializedSyntaxSet::FromBinary(data) => {
321
321
from_binary(data)
322
322
},
323
-
SerializedSyntaxSet::FromFile(refpath) => {
324
-
asset_from_cache(&path,"syntax set").expect("cache corrupt, consider rebuilding or clearing, see https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions on how")
323
+
SerializedSyntaxSet::FromFile(refdata) => {
324
+
from_reader(&data[..]).expect("cache corrupt, consider rebuilding or clearing, see https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions on how")
0 commit comments