]> git.sesse.net Git - plocate/blobdiff - plocate.cpp
Reuse zstd compression contexts, for a tiny speed boost.
[plocate] / plocate.cpp
index eb00adac8cced544b8ef0db9524f85cfcd146722..62bc6e331d04a9e61bf76b479258109e50bda100 100644 (file)
@@ -316,8 +316,9 @@ void scan_file_block(const vector<Needle> &needles, string_view compressed,
        string block;
        block.resize(uncompressed_len + 1);
 
-       size_t err = ZSTD_decompress(&block[0], block.size(), compressed.data(),
-                                    compressed.size());
+       static ZSTD_DCtx *ctx = ZSTD_createDCtx();  // Reused across calls.
+       size_t err = ZSTD_decompressDCtx(ctx, &block[0], block.size(), compressed.data(),
+                                        compressed.size());
        if (ZSTD_isError(err)) {
                fprintf(stderr, "ZSTD_decompress(): %s\n", ZSTD_getErrorName(err));
                exit(1);