]> git.sesse.net Git - plocate/blobdiff - plocate-build.cpp
Reuse zstd compression contexts, for a tiny speed boost.
[plocate] / plocate-build.cpp
index e1e2f644ef2ca891f93d48fdaab15e4f681bf418..ed252fc5a5ac755efb23b6d1ea621d3d28e3cd37 100644 (file)
@@ -300,7 +300,8 @@ string zstd_compress(const string &src, string *tempbuf)
        if (tempbuf->size() < max_size) {
                tempbuf->resize(max_size);
        }
-       size_t size = ZSTD_compress(&(*tempbuf)[0], max_size, src.data(), src.size(), /*level=*/6);
+       static ZSTD_CCtx *ctx = ZSTD_createCCtx();  // Reused across calls.
+       size_t size = ZSTD_compressCCtx(ctx, &(*tempbuf)[0], max_size, src.data(), src.size(), /*level=*/6);
        return string(tempbuf->data(), size);
 }