]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added ZSTD_createDDict_byReference() body
authorYann Collet <cyan@fb.com>
Wed, 21 Dec 2016 18:25:15 +0000 (19:25 +0100)
committerYann Collet <cyan@fb.com>
Wed, 21 Dec 2016 18:25:15 +0000 (19:25 +0100)
lib/common/mem.h
lib/decompress/zstd_decompress.c
lib/dictBuilder/zdict.c

index 32c63dd1763c17819eae402fe9691b7bfe383d05..aff044de13ed87639db5d001cf127b5857552bff 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 #endif
 
 /* code only tested on 32 and 64 bits systems */
-#define MEM_STATIC_ASSERT(c)   { enum { XXH_static_assert = 1/(int)(!!(c)) }; }
+#define MEM_STATIC_ASSERT(c)   { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
 MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
 
 
index 19e8287e222532d11bfb73d344e81e20bb2364b0..e976cd26d450903d66af4876a3f3a305be789891 100644 (file)
@@ -1766,6 +1766,18 @@ ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize)
     return ZSTD_createDDict_advanced(dict, dictSize, 0, allocator);
 }
 
+
+/*! ZSTD_createDDict_byReference() :
+ *  Create a digested dictionary, ready to start decompression operation without startup delay.
+ *  Dictionary content is simply referenced, and therefore stays in dictBuffer.
+ *  It is important that dictBuffer outlives DDict, it must remain read accessible throughout the lifetime of DDict */
+ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize)
+{
+    ZSTD_customMem const allocator = { NULL, NULL, NULL };
+    return ZSTD_createDDict_advanced(dictBuffer, dictSize, 1, allocator);
+}
+
+
 size_t ZSTD_freeDDict(ZSTD_DDict* ddict)
 {
     if (ddict==NULL) return 0;   /* support free on NULL */
index 921e37886ee2d6b65ff2defd129995b06c9a2828..ac22e870573b819944bb2df601000ccc2e6f4057 100644 (file)
@@ -306,13 +306,13 @@ static dictItem ZDICT_analyzePos(
         } while (length >=MINMATCHLENGTH);
 
         /* look backward */
-               length = MINMATCHLENGTH;
-               while ((length >= MINMATCHLENGTH) & (start > 0)) {
-                       length = ZDICT_count(b + pos, b + suffix[start - 1]);
-                       if (length >= LLIMIT) length = LLIMIT - 1;
-                       lengthList[length]++;
-                       if (length >= MINMATCHLENGTH) start--;
-               }
+        length = MINMATCHLENGTH;
+        while ((length >= MINMATCHLENGTH) & (start > 0)) {
+               length = ZDICT_count(b + pos, b + suffix[start - 1]);
+               if (length >= LLIMIT) length = LLIMIT - 1;
+               lengthList[length]++;
+               if (length >= MINMATCHLENGTH) start--;
+        }
 
         /* largest useful length */
         memset(cumulLength, 0, sizeof(cumulLength));