##// END OF EJS Templates
rust-inner-revlog: cache the compressor...
Raphaël Gomès -
r53201:7756494c default
parent child Browse files
Show More
@@ -52,6 +52,7 pub struct InnerRevlog {
52 /// Delta config that applies to this revlog
52 /// Delta config that applies to this revlog
53 delta_config: RevlogDeltaConfig,
53 delta_config: RevlogDeltaConfig,
54 /// Feature config that applies to this revlog
54 /// Feature config that applies to this revlog
55 #[allow(unused)]
55 feature_config: RevlogFeatureConfig,
56 feature_config: RevlogFeatureConfig,
56 /// A view into this revlog's data file
57 /// A view into this revlog's data file
57 segment_file: RandomAccessFile,
58 segment_file: RandomAccessFile,
@@ -71,6 +72,10 pub struct InnerRevlog {
71 /// A cache of the last revision, which is usually accessed multiple
72 /// A cache of the last revision, which is usually accessed multiple
72 /// times.
73 /// times.
73 pub last_revision_cache: Mutex<Option<SingleRevisionCache>>,
74 pub last_revision_cache: Mutex<Option<SingleRevisionCache>>,
75 /// The [`Compressor`] that this revlog uses by default to compress data.
76 /// This does not mean that this revlog uses this compressor for reading
77 /// data, as different revisions may have different compression modes.
78 compressor: Mutex<Box<dyn Compressor + Send>>,
74 }
79 }
75
80
76 impl InnerRevlog {
81 impl InnerRevlog {
@@ -117,6 +122,15 impl InnerRevlog {
117 delayed_buffer: None,
122 delayed_buffer: None,
118 inline,
123 inline,
119 last_revision_cache: Mutex::new(None),
124 last_revision_cache: Mutex::new(None),
125 compressor: Mutex::new(match feature_config.compression_engine {
126 CompressionConfig::Zlib { level } => {
127 Box::new(ZlibCompressor::new(level))
128 }
129 CompressionConfig::Zstd { level, threads } => {
130 Box::new(ZstdCompressor::new(level, threads))
131 }
132 CompressionConfig::None => Box::new(NoneCompressor),
133 }),
120 }
134 }
121 }
135 }
122
136
@@ -286,19 +300,6 impl InnerRevlog {
286 )
300 )
287 }
301 }
288
302
289 fn compressor(&self) -> Result<Box<dyn Compressor>, HgError> {
290 // TODO cache the compressor?
291 Ok(match self.feature_config.compression_engine {
292 CompressionConfig::Zlib { level } => {
293 Box::new(ZlibCompressor::new(level))
294 }
295 CompressionConfig::Zstd { level, threads } => {
296 Box::new(ZstdCompressor::new(level, threads))
297 }
298 CompressionConfig::None => Box::new(NoneCompressor),
299 })
300 }
301
302 /// Generate a possibly-compressed representation of data.
303 /// Generate a possibly-compressed representation of data.
303 /// Returns `None` if the data was not compressed.
304 /// Returns `None` if the data was not compressed.
304 pub fn compress<'data>(
305 pub fn compress<'data>(
@@ -308,7 +309,7 impl InnerRevlog {
308 if data.is_empty() {
309 if data.is_empty() {
309 return Ok(Some(data.into()));
310 return Ok(Some(data.into()));
310 }
311 }
311 let res = self.compressor()?.compress(data)?;
312 let res = self.compressor.lock().unwrap().compress(data)?;
312 if let Some(compressed) = res {
313 if let Some(compressed) = res {
313 // The revlog compressor added the header in the returned data.
314 // The revlog compressor added the header in the returned data.
314 return Ok(Some(compressed.into()));
315 return Ok(Some(compressed.into()));
General Comments 0
You need to be logged in to leave comments. Login now