Show More
@@ -596,13 +596,26 b" impl<'revlog> RevlogEntry<'revlog> {" | |||
|
596 | 596 | } |
|
597 | 597 | |
|
598 | 598 | fn uncompressed_zstd_data(&self) -> Result<Vec<u8>, HgError> { |
|
599 | let cap = self.uncompressed_len.max(0) as usize; | |
|
599 | 600 | if self.is_delta() { |
|
600 | let mut buf = Vec::with_capacity(self.compressed_len as usize); | |
|
601 | zstd::stream::copy_decode(self.bytes, &mut buf) | |
|
602 | .map_err(|e| corrupted(e.to_string()))?; | |
|
601 | // [cap] is usually an over-estimate of the space needed because | |
|
602 | // it's the length of delta-decoded data, but we're interested | |
|
603 | // in the size of the delta. | |
|
604 | // This means we have to [shrink_to_fit] to avoid holding on | |
|
605 | // to a large chunk of memory, but it also means we must have a | |
|
606 | // fallback branch, for the case when the delta is longer than | |
|
607 | // the original data (surprisingly, this does happen in practice) | |
|
608 | let mut buf = Vec::with_capacity(cap); | |
|
609 | match zstd_decompress_to_buffer(self.bytes, &mut buf) { | |
|
610 | Ok(_) => buf.shrink_to_fit(), | |
|
611 | Err(_) => { | |
|
612 | buf.clear(); | |
|
613 | zstd::stream::copy_decode(self.bytes, &mut buf) | |
|
614 | .map_err(|e| corrupted(e.to_string()))?; | |
|
615 | } | |
|
616 | }; | |
|
603 | 617 | Ok(buf) |
|
604 | 618 | } else { |
|
605 | let cap = self.uncompressed_len.max(0) as usize; | |
|
606 | 619 | let mut buf = Vec::with_capacity(cap); |
|
607 | 620 | let len = zstd_decompress_to_buffer(self.bytes, &mut buf) |
|
608 | 621 | .map_err(|e| corrupted(e.to_string()))?; |
General Comments 0
You need to be logged in to leave comments.
Login now