Show More
@@ -23,6 +23,7 b' use std::path::Path;' | |||||
23 |
|
23 | |||
24 | use flate2::read::ZlibDecoder; |
|
24 | use flate2::read::ZlibDecoder; | |
25 | use sha1::{Digest, Sha1}; |
|
25 | use sha1::{Digest, Sha1}; | |
|
26 | use std::cell::RefCell; | |||
26 | use zstd; |
|
27 | use zstd; | |
27 |
|
28 | |||
28 | use self::node::{NODE_BYTES_LENGTH, NULL_NODE}; |
|
29 | use self::node::{NODE_BYTES_LENGTH, NULL_NODE}; | |
@@ -413,6 +414,21 b" pub struct RevlogEntry<'revlog> {" | |||||
413 | hash: Node, |
|
414 | hash: Node, | |
414 | } |
|
415 | } | |
415 |
|
416 | |||
|
417 | thread_local! { | |||
|
418 | // seems fine to [unwrap] here: this can only fail due to memory allocation | |||
|
419 | // failing, and it's normal for that to cause panic. | |||
|
420 | static ZSTD_DECODER : RefCell<zstd::bulk::Decompressor<'static>> = | |||
|
421 | RefCell::new(zstd::bulk::Decompressor::new().ok().unwrap()); | |||
|
422 | } | |||
|
423 | ||||
|
424 | fn zstd_decompress_to_buffer( | |||
|
425 | bytes: &[u8], | |||
|
426 | buf: &mut Vec<u8>, | |||
|
427 | ) -> Result<usize, std::io::Error> { | |||
|
428 | ZSTD_DECODER | |||
|
429 | .with(|decoder| decoder.borrow_mut().decompress_to_buffer(bytes, buf)) | |||
|
430 | } | |||
|
431 | ||||
416 | impl<'revlog> RevlogEntry<'revlog> { |
|
432 | impl<'revlog> RevlogEntry<'revlog> { | |
417 | pub fn revision(&self) -> Revision { |
|
433 | pub fn revision(&self) -> Revision { | |
418 | self.rev |
|
434 | self.rev | |
@@ -588,7 +604,7 b" impl<'revlog> RevlogEntry<'revlog> {" | |||||
588 | } else { |
|
604 | } else { | |
589 | let cap = self.uncompressed_len.max(0) as usize; |
|
605 | let cap = self.uncompressed_len.max(0) as usize; | |
590 | let mut buf = vec![0; cap]; |
|
606 | let mut buf = vec![0; cap]; | |
591 |
let len = zstd |
|
607 | let len = zstd_decompress_to_buffer(self.bytes, &mut buf) | |
592 | .map_err(|e| corrupted(e.to_string()))?; |
|
608 | .map_err(|e| corrupted(e.to_string()))?; | |
593 | if len != self.uncompressed_len as usize { |
|
609 | if len != self.uncompressed_len as usize { | |
594 | Err(corrupted("uncompressed length does not match")) |
|
610 | Err(corrupted("uncompressed length does not match")) |
General Comments 0
You need to be logged in to leave comments.
Login now