]> git.sesse.net Git - plocate/blobdiff - plocate.cpp
Reuse zstd compression contexts, for a tiny speed boost.
[plocate] / plocate.cpp
index 63a927febe8091a5dbd7220ad6f0ebba925742ed..62bc6e331d04a9e61bf76b479258109e50bda100 100644 (file)
@@ -58,7 +58,7 @@ void apply_limit()
        dprintf("Done in %.1f ms, found %" PRId64 " matches.\n",
                1e3 * duration<float>(steady_clock::now() - start).count(), limit_matches);
        if (only_count) {
-               printf("%ld\n", limit_matches);
+               printf("%" PRId64 "\n", limit_matches);
        }
        exit(0);
 }
@@ -305,7 +305,7 @@ size_t Corpus::get_num_filename_blocks() const
 
 void scan_file_block(const vector<Needle> &needles, string_view compressed,
                      AccessRXCache *access_rx_cache, uint64_t seq, Serializer *serializer,
-                     size_t *matched)
+                     uint64_t *matched)
 {
        unsigned long long uncompressed_len = ZSTD_getFrameContentSize(compressed.data(), compressed.size());
        if (uncompressed_len == ZSTD_CONTENTSIZE_UNKNOWN || uncompressed_len == ZSTD_CONTENTSIZE_ERROR) {
@@ -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);