mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-22 18:52:07 +08:00
replay: optimize decompressZST with pre-allocated buffer (#33562)
improve decompressZST
This commit is contained in:
+10
-1
@@ -329,8 +329,17 @@ std::string decompressZST(const std::byte *in, size_t in_size, std::atomic<bool>
|
||||
|
||||
// Initialize input and output buffers
|
||||
ZSTD_inBuffer input = {in, in_size, 0};
|
||||
|
||||
// Estimate and reserve memory for decompressed data
|
||||
size_t estimatedDecompressedSize = ZSTD_getFrameContentSize(in, in_size);
|
||||
if (estimatedDecompressedSize == ZSTD_CONTENTSIZE_ERROR || estimatedDecompressedSize == ZSTD_CONTENTSIZE_UNKNOWN) {
|
||||
estimatedDecompressedSize = in_size * 2; // Use a fallback size
|
||||
}
|
||||
|
||||
std::string decompressedData;
|
||||
const size_t bufferSize = ZSTD_DStreamOutSize(); // recommended output buffer size
|
||||
decompressedData.reserve(estimatedDecompressedSize);
|
||||
|
||||
const size_t bufferSize = ZSTD_DStreamOutSize(); // Recommended output buffer size
|
||||
std::string outputBuffer(bufferSize, '\0');
|
||||
|
||||
while (input.pos < input.size && !(abort && *abort)) {
|
||||
|
||||
Reference in New Issue
Block a user