zstd-ruby 1.3.5.0 → 1.3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/README.md +2 -1
- data/ext/zstdruby/libzstd/BUCK +1 -0
- data/ext/zstdruby/libzstd/Makefile +25 -13
- data/ext/zstdruby/libzstd/README.md +11 -10
- data/ext/zstdruby/libzstd/common/bitstream.h +8 -11
- data/ext/zstdruby/libzstd/common/compiler.h +30 -8
- data/ext/zstdruby/libzstd/common/cpu.h +1 -1
- data/ext/zstdruby/libzstd/common/mem.h +20 -2
- data/ext/zstdruby/libzstd/common/xxhash.c +1 -0
- data/ext/zstdruby/libzstd/common/zstd_internal.h +3 -2
- data/ext/zstdruby/libzstd/compress/fse_compress.c +55 -48
- data/ext/zstdruby/libzstd/compress/hist.h +1 -1
- data/ext/zstdruby/libzstd/compress/huf_compress.c +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +290 -147
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +5 -2
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +63 -51
- data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +3 -4
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +44 -33
- data/ext/zstdruby/libzstd/compress/zstd_fast.h +3 -4
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +125 -116
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +13 -15
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +9 -11
- data/ext/zstdruby/libzstd/compress/zstd_ldm.h +0 -1
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +42 -36
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +8 -9
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +96 -51
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +16 -6
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +3 -3
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +169 -101
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +111 -87
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +83 -0
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +3 -3
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +728 -0
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +34 -31
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +60 -5
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +9 -3
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +6 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +6 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +1 -5
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +12 -9
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +10 -10
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +20 -18
- data/ext/zstdruby/libzstd/zstd.h +109 -50
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +4 -2
| @@ -140,6 +140,7 @@ struct ZSTD_matchState_t { | |
| 140 140 | 
             
                U32* chainTable;
         | 
| 141 141 | 
             
                optState_t opt;         /* optimal parser state */
         | 
| 142 142 | 
             
                const ZSTD_matchState_t *dictMatchState;
         | 
| 143 | 
            +
                ZSTD_compressionParameters cParams;
         | 
| 143 144 | 
             
            };
         | 
| 144 145 |  | 
| 145 146 | 
             
            typedef struct {
         | 
| @@ -264,7 +265,7 @@ typedef enum { ZSTD_noDict = 0, ZSTD_extDict = 1, ZSTD_dictMatchState = 2 } ZSTD | |
| 264 265 |  | 
| 265 266 | 
             
            typedef size_t (*ZSTD_blockCompressor) (
         | 
| 266 267 | 
             
                    ZSTD_matchState_t* bs, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 267 | 
            -
                     | 
| 268 | 
            +
                    void const* src, size_t srcSize);
         | 
| 268 269 | 
             
            ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, ZSTD_dictMode_e dictMode);
         | 
| 269 270 |  | 
| 270 271 |  | 
| @@ -314,8 +315,10 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const v | |
| 314 315 | 
             
                           pos, (U32)litLength, (U32)mlBase+MINMATCH, (U32)offsetCode);
         | 
| 315 316 | 
             
                }
         | 
| 316 317 | 
             
            #endif
         | 
| 318 | 
            +
                assert((size_t)(seqStorePtr->sequences - seqStorePtr->sequencesStart) < seqStorePtr->maxNbSeq);
         | 
| 317 319 | 
             
                /* copy Literals */
         | 
| 318 | 
            -
                assert(seqStorePtr-> | 
| 320 | 
            +
                assert(seqStorePtr->maxNbLit <= 128 KB);
         | 
| 321 | 
            +
                assert(seqStorePtr->lit + litLength <= seqStorePtr->litStart + seqStorePtr->maxNbLit);
         | 
| 319 322 | 
             
                ZSTD_wildcopy(seqStorePtr->lit, literals, litLength);
         | 
| 320 323 | 
             
                seqStorePtr->lit += litLength;
         | 
| 321 324 |  | 
| @@ -13,9 +13,9 @@ | |
| 13 13 |  | 
| 14 14 |  | 
| 15 15 | 
             
            void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
         | 
| 16 | 
            -
                                          ZSTD_compressionParameters const* cParams,
         | 
| 17 16 | 
             
                                          void const* end, ZSTD_dictTableLoadMethod_e dtlm)
         | 
| 18 17 | 
             
            {
         | 
| 18 | 
            +
                const ZSTD_compressionParameters* const cParams = &ms->cParams;
         | 
| 19 19 | 
             
                U32* const hashLarge = ms->hashTable;
         | 
| 20 20 | 
             
                U32  const hBitsL = cParams->hashLog;
         | 
| 21 21 | 
             
                U32  const mls = cParams->searchLength;
         | 
| @@ -51,9 +51,10 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms, | |
| 51 51 | 
             
            FORCE_INLINE_TEMPLATE
         | 
| 52 52 | 
             
            size_t ZSTD_compressBlock_doubleFast_generic(
         | 
| 53 53 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 54 | 
            -
                     | 
| 54 | 
            +
                    void const* src, size_t srcSize,
         | 
| 55 55 | 
             
                    U32 const mls /* template */, ZSTD_dictMode_e const dictMode)
         | 
| 56 56 | 
             
            {
         | 
| 57 | 
            +
                ZSTD_compressionParameters const* cParams = &ms->cParams;
         | 
| 57 58 | 
             
                U32* const hashLong = ms->hashTable;
         | 
| 58 59 | 
             
                const U32 hBitsL = cParams->hashLog;
         | 
| 59 60 | 
             
                U32* const hashSmall = ms->chainTable;
         | 
| @@ -70,6 +71,9 @@ size_t ZSTD_compressBlock_doubleFast_generic( | |
| 70 71 | 
             
                U32 offsetSaved = 0;
         | 
| 71 72 |  | 
| 72 73 | 
             
                const ZSTD_matchState_t* const dms = ms->dictMatchState;
         | 
| 74 | 
            +
                const ZSTD_compressionParameters* const dictCParams =
         | 
| 75 | 
            +
                                                 dictMode == ZSTD_dictMatchState ?
         | 
| 76 | 
            +
                                                 &dms->cParams : NULL;
         | 
| 73 77 | 
             
                const U32* const dictHashLong  = dictMode == ZSTD_dictMatchState ?
         | 
| 74 78 | 
             
                                                 dms->hashTable : NULL;
         | 
| 75 79 | 
             
                const U32* const dictHashSmall = dictMode == ZSTD_dictMatchState ?
         | 
| @@ -85,6 +89,10 @@ size_t ZSTD_compressBlock_doubleFast_generic( | |
| 85 89 | 
             
                const U32 dictIndexDelta       = dictMode == ZSTD_dictMatchState ?
         | 
| 86 90 | 
             
                                                 prefixLowestIndex - (U32)(dictEnd - dictBase) :
         | 
| 87 91 | 
             
                                                 0;
         | 
| 92 | 
            +
                const U32 dictHBitsL           = dictMode == ZSTD_dictMatchState ?
         | 
| 93 | 
            +
                                                 dictCParams->hashLog : hBitsL;
         | 
| 94 | 
            +
                const U32 dictHBitsS           = dictMode == ZSTD_dictMatchState ?
         | 
| 95 | 
            +
                                                 dictCParams->chainLog : hBitsS;
         | 
| 88 96 | 
             
                const U32 dictAndPrefixLength  = (U32)(ip - prefixLowest + dictEnd - dictStart);
         | 
| 89 97 |  | 
| 90 98 | 
             
                assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
         | 
| @@ -109,6 +117,8 @@ size_t ZSTD_compressBlock_doubleFast_generic( | |
| 109 117 | 
             
                    U32 offset;
         | 
| 110 118 | 
             
                    size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8);
         | 
| 111 119 | 
             
                    size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
         | 
| 120 | 
            +
                    size_t const dictHL = ZSTD_hashPtr(ip, dictHBitsL, 8);
         | 
| 121 | 
            +
                    size_t const dictHS = ZSTD_hashPtr(ip, dictHBitsS, mls);
         | 
| 112 122 | 
             
                    U32 const current = (U32)(ip-base);
         | 
| 113 123 | 
             
                    U32 const matchIndexL = hashLong[h2];
         | 
| 114 124 | 
             
                    U32 matchIndexS = hashSmall[h];
         | 
| @@ -141,17 +151,17 @@ size_t ZSTD_compressBlock_doubleFast_generic( | |
| 141 151 | 
             
                        goto _match_stored;
         | 
| 142 152 | 
             
                    }
         | 
| 143 153 |  | 
| 144 | 
            -
                     | 
| 145 | 
            -
             | 
| 146 | 
            -
                         | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
                     | 
| 153 | 
            -
             | 
| 154 | 
            -
                        U32 const dictMatchIndexL = dictHashLong[ | 
| 154 | 
            +
                    if (matchIndexL > prefixLowestIndex) {
         | 
| 155 | 
            +
                        /* check prefix long match */
         | 
| 156 | 
            +
                        if (MEM_read64(matchLong) == MEM_read64(ip)) {
         | 
| 157 | 
            +
                            mLength = ZSTD_count(ip+8, matchLong+8, iend) + 8;
         | 
| 158 | 
            +
                            offset = (U32)(ip-matchLong);
         | 
| 159 | 
            +
                            while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
         | 
| 160 | 
            +
                            goto _match_found;
         | 
| 161 | 
            +
                        }
         | 
| 162 | 
            +
                    } else if (dictMode == ZSTD_dictMatchState) {
         | 
| 163 | 
            +
                        /* check dictMatchState long match */
         | 
| 164 | 
            +
                        U32 const dictMatchIndexL = dictHashLong[dictHL];
         | 
| 155 165 | 
             
                        const BYTE* dictMatchL = dictBase + dictMatchIndexL;
         | 
| 156 166 | 
             
                        assert(dictMatchL < dictEnd);
         | 
| 157 167 |  | 
| @@ -163,14 +173,14 @@ size_t ZSTD_compressBlock_doubleFast_generic( | |
| 163 173 | 
             
                        }
         | 
| 164 174 | 
             
                    }
         | 
| 165 175 |  | 
| 166 | 
            -
                     | 
| 167 | 
            -
             | 
| 168 | 
            -
                         | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
                     | 
| 172 | 
            -
             | 
| 173 | 
            -
                        U32 const dictMatchIndexS = dictHashSmall[ | 
| 176 | 
            +
                    if (matchIndexS > prefixLowestIndex) {
         | 
| 177 | 
            +
                        /* check prefix short match */
         | 
| 178 | 
            +
                        if (MEM_read32(match) == MEM_read32(ip)) {
         | 
| 179 | 
            +
                            goto _search_next_long;
         | 
| 180 | 
            +
                        }
         | 
| 181 | 
            +
                    } else if (dictMode == ZSTD_dictMatchState) {
         | 
| 182 | 
            +
                        /* check dictMatchState short match */
         | 
| 183 | 
            +
                        U32 const dictMatchIndexS = dictHashSmall[dictHS];
         | 
| 174 184 | 
             
                        match = dictBase + dictMatchIndexS;
         | 
| 175 185 | 
             
                        matchIndexS = dictMatchIndexS + dictIndexDelta;
         | 
| 176 186 |  | 
| @@ -186,22 +196,23 @@ _search_next_long: | |
| 186 196 |  | 
| 187 197 | 
             
                    {
         | 
| 188 198 | 
             
                        size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
         | 
| 199 | 
            +
                        size_t const dictHLNext = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
         | 
| 189 200 | 
             
                        U32 const matchIndexL3 = hashLong[hl3];
         | 
| 190 201 | 
             
                        const BYTE* matchL3 = base + matchIndexL3;
         | 
| 191 202 | 
             
                        hashLong[hl3] = current + 1;
         | 
| 192 203 |  | 
| 193 204 | 
             
                        /* check prefix long +1 match */
         | 
| 194 | 
            -
                        if ( | 
| 195 | 
            -
                             | 
| 196 | 
            -
             | 
| 197 | 
            -
             | 
| 198 | 
            -
             | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 202 | 
            -
                         | 
| 203 | 
            -
             | 
| 204 | 
            -
                            U32 const dictMatchIndexL3 = dictHashLong[ | 
| 205 | 
            +
                        if (matchIndexL3 > prefixLowestIndex) {
         | 
| 206 | 
            +
                            if (MEM_read64(matchL3) == MEM_read64(ip+1)) {
         | 
| 207 | 
            +
                                mLength = ZSTD_count(ip+9, matchL3+8, iend) + 8;
         | 
| 208 | 
            +
                                ip++;
         | 
| 209 | 
            +
                                offset = (U32)(ip-matchL3);
         | 
| 210 | 
            +
                                while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
         | 
| 211 | 
            +
                                goto _match_found;
         | 
| 212 | 
            +
                            }
         | 
| 213 | 
            +
                        } else if (dictMode == ZSTD_dictMatchState) {
         | 
| 214 | 
            +
                            /* check dict long +1 match */
         | 
| 215 | 
            +
                            U32 const dictMatchIndexL3 = dictHashLong[dictHLNext];
         | 
| 205 216 | 
             
                            const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
         | 
| 206 217 | 
             
                            assert(dictMatchL3 < dictEnd);
         | 
| 207 218 | 
             
                            if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
         | 
| @@ -296,49 +307,50 @@ _match_stored: | |
| 296 307 |  | 
| 297 308 | 
             
            size_t ZSTD_compressBlock_doubleFast(
         | 
| 298 309 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 299 | 
            -
                     | 
| 310 | 
            +
                    void const* src, size_t srcSize)
         | 
| 300 311 | 
             
            {
         | 
| 301 | 
            -
                const U32 mls = cParams | 
| 312 | 
            +
                const U32 mls = ms->cParams.searchLength;
         | 
| 302 313 | 
             
                switch(mls)
         | 
| 303 314 | 
             
                {
         | 
| 304 315 | 
             
                default: /* includes case 3 */
         | 
| 305 316 | 
             
                case 4 :
         | 
| 306 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 317 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_noDict);
         | 
| 307 318 | 
             
                case 5 :
         | 
| 308 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 319 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_noDict);
         | 
| 309 320 | 
             
                case 6 :
         | 
| 310 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 321 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_noDict);
         | 
| 311 322 | 
             
                case 7 :
         | 
| 312 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 323 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_noDict);
         | 
| 313 324 | 
             
                }
         | 
| 314 325 | 
             
            }
         | 
| 315 326 |  | 
| 316 327 |  | 
| 317 328 | 
             
            size_t ZSTD_compressBlock_doubleFast_dictMatchState(
         | 
| 318 329 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 319 | 
            -
                     | 
| 330 | 
            +
                    void const* src, size_t srcSize)
         | 
| 320 331 | 
             
            {
         | 
| 321 | 
            -
                const U32 mls = cParams | 
| 332 | 
            +
                const U32 mls = ms->cParams.searchLength;
         | 
| 322 333 | 
             
                switch(mls)
         | 
| 323 334 | 
             
                {
         | 
| 324 335 | 
             
                default: /* includes case 3 */
         | 
| 325 336 | 
             
                case 4 :
         | 
| 326 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 337 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_dictMatchState);
         | 
| 327 338 | 
             
                case 5 :
         | 
| 328 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 339 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_dictMatchState);
         | 
| 329 340 | 
             
                case 6 :
         | 
| 330 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 341 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_dictMatchState);
         | 
| 331 342 | 
             
                case 7 :
         | 
| 332 | 
            -
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep,  | 
| 343 | 
            +
                    return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_dictMatchState);
         | 
| 333 344 | 
             
                }
         | 
| 334 345 | 
             
            }
         | 
| 335 346 |  | 
| 336 347 |  | 
| 337 348 | 
             
            static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
         | 
| 338 349 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 339 | 
            -
                     | 
| 350 | 
            +
                    void const* src, size_t srcSize,
         | 
| 340 351 | 
             
                    U32 const mls /* template */)
         | 
| 341 352 | 
             
            {
         | 
| 353 | 
            +
                ZSTD_compressionParameters const* cParams = &ms->cParams;
         | 
| 342 354 | 
             
                U32* const hashLong = ms->hashTable;
         | 
| 343 355 | 
             
                U32  const hBitsL = cParams->hashLog;
         | 
| 344 356 | 
             
                U32* const hashSmall = ms->chainTable;
         | 
| @@ -469,19 +481,19 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic( | |
| 469 481 |  | 
| 470 482 | 
             
            size_t ZSTD_compressBlock_doubleFast_extDict(
         | 
| 471 483 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 472 | 
            -
                     | 
| 484 | 
            +
                    void const* src, size_t srcSize)
         | 
| 473 485 | 
             
            {
         | 
| 474 | 
            -
                U32 const mls = cParams | 
| 486 | 
            +
                U32 const mls = ms->cParams.searchLength;
         | 
| 475 487 | 
             
                switch(mls)
         | 
| 476 488 | 
             
                {
         | 
| 477 489 | 
             
                default: /* includes case 3 */
         | 
| 478 490 | 
             
                case 4 :
         | 
| 479 | 
            -
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep,  | 
| 491 | 
            +
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 4);
         | 
| 480 492 | 
             
                case 5 :
         | 
| 481 | 
            -
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep,  | 
| 493 | 
            +
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 5);
         | 
| 482 494 | 
             
                case 6 :
         | 
| 483 | 
            -
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep,  | 
| 495 | 
            +
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 6);
         | 
| 484 496 | 
             
                case 7 :
         | 
| 485 | 
            -
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep,  | 
| 497 | 
            +
                    return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 7);
         | 
| 486 498 | 
             
                }
         | 
| 487 499 | 
             
            }
         | 
| @@ -19,17 +19,16 @@ extern "C" { | |
| 19 19 | 
             
            #include "zstd_compress_internal.h"     /* ZSTD_CCtx, size_t */
         | 
| 20 20 |  | 
| 21 21 | 
             
            void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
         | 
| 22 | 
            -
                                          ZSTD_compressionParameters const* cParams,
         | 
| 23 22 | 
             
                                          void const* end, ZSTD_dictTableLoadMethod_e dtlm);
         | 
| 24 23 | 
             
            size_t ZSTD_compressBlock_doubleFast(
         | 
| 25 24 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 26 | 
            -
                     | 
| 25 | 
            +
                    void const* src, size_t srcSize);
         | 
| 27 26 | 
             
            size_t ZSTD_compressBlock_doubleFast_dictMatchState(
         | 
| 28 27 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 29 | 
            -
                     | 
| 28 | 
            +
                    void const* src, size_t srcSize);
         | 
| 30 29 | 
             
            size_t ZSTD_compressBlock_doubleFast_extDict(
         | 
| 31 30 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 32 | 
            -
                     | 
| 31 | 
            +
                    void const* src, size_t srcSize);
         | 
| 33 32 |  | 
| 34 33 |  | 
| 35 34 | 
             
            #if defined (__cplusplus)
         | 
| @@ -13,9 +13,9 @@ | |
| 13 13 |  | 
| 14 14 |  | 
| 15 15 | 
             
            void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
         | 
| 16 | 
            -
                                    ZSTD_compressionParameters const* cParams,
         | 
| 17 16 | 
             
                                    void const* end, ZSTD_dictTableLoadMethod_e dtlm)
         | 
| 18 17 | 
             
            {
         | 
| 18 | 
            +
                const ZSTD_compressionParameters* const cParams = &ms->cParams;
         | 
| 19 19 | 
             
                U32* const hashTable = ms->hashTable;
         | 
| 20 20 | 
             
                U32  const hBits = cParams->hashLog;
         | 
| 21 21 | 
             
                U32  const mls = cParams->searchLength;
         | 
| @@ -45,10 +45,13 @@ FORCE_INLINE_TEMPLATE | |
| 45 45 | 
             
            size_t ZSTD_compressBlock_fast_generic(
         | 
| 46 46 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 47 47 | 
             
                    void const* src, size_t srcSize,
         | 
| 48 | 
            -
                    U32 const  | 
| 49 | 
            -
                    ZSTD_dictMode_e const dictMode)
         | 
| 48 | 
            +
                    U32 const mls, ZSTD_dictMode_e const dictMode)
         | 
| 50 49 | 
             
            {
         | 
| 50 | 
            +
                const ZSTD_compressionParameters* const cParams = &ms->cParams;
         | 
| 51 51 | 
             
                U32* const hashTable = ms->hashTable;
         | 
| 52 | 
            +
                U32 const hlog = cParams->hashLog;
         | 
| 53 | 
            +
                /* support stepSize of 0 */
         | 
| 54 | 
            +
                U32 const stepSize = cParams->targetLength + !(cParams->targetLength);
         | 
| 52 55 | 
             
                const BYTE* const base = ms->window.base;
         | 
| 53 56 | 
             
                const BYTE* const istart = (const BYTE*)src;
         | 
| 54 57 | 
             
                const BYTE* ip = istart;
         | 
| @@ -61,6 +64,9 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 61 64 | 
             
                U32 offsetSaved = 0;
         | 
| 62 65 |  | 
| 63 66 | 
             
                const ZSTD_matchState_t* const dms = ms->dictMatchState;
         | 
| 67 | 
            +
                const ZSTD_compressionParameters* const dictCParams =
         | 
| 68 | 
            +
                                                 dictMode == ZSTD_dictMatchState ?
         | 
| 69 | 
            +
                                                 &dms->cParams : NULL;
         | 
| 64 70 | 
             
                const U32* const dictHashTable = dictMode == ZSTD_dictMatchState ?
         | 
| 65 71 | 
             
                                                 dms->hashTable : NULL;
         | 
| 66 72 | 
             
                const U32 dictStartIndex       = dictMode == ZSTD_dictMatchState ?
         | 
| @@ -75,6 +81,8 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 75 81 | 
             
                                                 prefixStartIndex - (U32)(dictEnd - dictBase) :
         | 
| 76 82 | 
             
                                                 0;
         | 
| 77 83 | 
             
                const U32 dictAndPrefixLength  = (U32)(ip - prefixStart + dictEnd - dictStart);
         | 
| 84 | 
            +
                const U32 dictHLog             = dictMode == ZSTD_dictMatchState ?
         | 
| 85 | 
            +
                                                 dictCParams->hashLog : hlog;
         | 
| 78 86 |  | 
| 79 87 | 
             
                assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
         | 
| 80 88 |  | 
| @@ -84,7 +92,6 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 84 92 | 
             
                    || prefixStartIndex >= (U32)(dictEnd - dictBase));
         | 
| 85 93 |  | 
| 86 94 | 
             
                /* init */
         | 
| 87 | 
            -
                stepSize += !stepSize;  /* support stepSize of 0 */
         | 
| 88 95 | 
             
                ip += (dictAndPrefixLength == 0);
         | 
| 89 96 | 
             
                if (dictMode == ZSTD_noDict) {
         | 
| 90 97 | 
             
                    U32 const maxRep = (U32)(ip - prefixStart);
         | 
| @@ -124,10 +131,10 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 124 131 | 
             
                        mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
         | 
| 125 132 | 
             
                        ip++;
         | 
| 126 133 | 
             
                        ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
         | 
| 127 | 
            -
                    } else if ( (matchIndex <= prefixStartIndex)
         | 
| 128 | 
            -
                             || (MEM_read32(match) != MEM_read32(ip)) ) {
         | 
| 134 | 
            +
                    } else if ( (matchIndex <= prefixStartIndex) ) {
         | 
| 129 135 | 
             
                        if (dictMode == ZSTD_dictMatchState) {
         | 
| 130 | 
            -
                             | 
| 136 | 
            +
                            size_t const dictHash = ZSTD_hashPtr(ip, dictHLog, mls);
         | 
| 137 | 
            +
                            U32 const dictMatchIndex = dictHashTable[dictHash];
         | 
| 131 138 | 
             
                            const BYTE* dictMatch = dictBase + dictMatchIndex;
         | 
| 132 139 | 
             
                            if (dictMatchIndex <= dictStartIndex ||
         | 
| 133 140 | 
             
                                MEM_read32(dictMatch) != MEM_read32(ip)) {
         | 
| @@ -151,6 +158,11 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 151 158 | 
             
                            ip += ((ip-anchor) >> kSearchStrength) + stepSize;
         | 
| 152 159 | 
             
                            continue;
         | 
| 153 160 | 
             
                        }
         | 
| 161 | 
            +
                    } else if (MEM_read32(match) != MEM_read32(ip)) {
         | 
| 162 | 
            +
                        /* it's not a match, and we're not going to check the dictionary */
         | 
| 163 | 
            +
                        assert(stepSize >= 1);
         | 
| 164 | 
            +
                        ip += ((ip-anchor) >> kSearchStrength) + stepSize;
         | 
| 165 | 
            +
                        continue;
         | 
| 154 166 | 
             
                    } else {
         | 
| 155 167 | 
             
                        /* found a regular match */
         | 
| 156 168 | 
             
                        U32 const offset = (U32)(ip-match);
         | 
| @@ -168,6 +180,7 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 168 180 |  | 
| 169 181 | 
             
                    if (ip <= ilimit) {
         | 
| 170 182 | 
             
                        /* Fill Table */
         | 
| 183 | 
            +
                        assert(base+current+2 > istart);  /* check base overflow */
         | 
| 171 184 | 
             
                        hashTable[ZSTD_hashPtr(base+current+2, hlog, mls)] = current+2;  /* here because current+2 could be > iend-8 */
         | 
| 172 185 | 
             
                        hashTable[ZSTD_hashPtr(ip-2, hlog, mls)] = (U32)(ip-2-base);
         | 
| 173 186 |  | 
| @@ -219,55 +232,56 @@ size_t ZSTD_compressBlock_fast_generic( | |
| 219 232 |  | 
| 220 233 | 
             
            size_t ZSTD_compressBlock_fast(
         | 
| 221 234 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 222 | 
            -
                     | 
| 235 | 
            +
                    void const* src, size_t srcSize)
         | 
| 223 236 | 
             
            {
         | 
| 224 | 
            -
                 | 
| 237 | 
            +
                ZSTD_compressionParameters const* cParams = &ms->cParams;
         | 
| 225 238 | 
             
                U32 const mls = cParams->searchLength;
         | 
| 226 | 
            -
                U32 const stepSize = cParams->targetLength;
         | 
| 227 239 | 
             
                assert(ms->dictMatchState == NULL);
         | 
| 228 240 | 
             
                switch(mls)
         | 
| 229 241 | 
             
                {
         | 
| 230 242 | 
             
                default: /* includes case 3 */
         | 
| 231 243 | 
             
                case 4 :
         | 
| 232 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 244 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_noDict);
         | 
| 233 245 | 
             
                case 5 :
         | 
| 234 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 246 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_noDict);
         | 
| 235 247 | 
             
                case 6 :
         | 
| 236 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 248 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_noDict);
         | 
| 237 249 | 
             
                case 7 :
         | 
| 238 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 250 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_noDict);
         | 
| 239 251 | 
             
                }
         | 
| 240 252 | 
             
            }
         | 
| 241 253 |  | 
| 242 254 | 
             
            size_t ZSTD_compressBlock_fast_dictMatchState(
         | 
| 243 255 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 244 | 
            -
                     | 
| 256 | 
            +
                    void const* src, size_t srcSize)
         | 
| 245 257 | 
             
            {
         | 
| 246 | 
            -
                 | 
| 258 | 
            +
                ZSTD_compressionParameters const* cParams = &ms->cParams;
         | 
| 247 259 | 
             
                U32 const mls = cParams->searchLength;
         | 
| 248 | 
            -
                U32 const stepSize = cParams->targetLength;
         | 
| 249 260 | 
             
                assert(ms->dictMatchState != NULL);
         | 
| 250 261 | 
             
                switch(mls)
         | 
| 251 262 | 
             
                {
         | 
| 252 263 | 
             
                default: /* includes case 3 */
         | 
| 253 264 | 
             
                case 4 :
         | 
| 254 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 265 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_dictMatchState);
         | 
| 255 266 | 
             
                case 5 :
         | 
| 256 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 267 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_dictMatchState);
         | 
| 257 268 | 
             
                case 6 :
         | 
| 258 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 269 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_dictMatchState);
         | 
| 259 270 | 
             
                case 7 :
         | 
| 260 | 
            -
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize,  | 
| 271 | 
            +
                    return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_dictMatchState);
         | 
| 261 272 | 
             
                }
         | 
| 262 273 | 
             
            }
         | 
| 263 274 |  | 
| 264 275 |  | 
| 265 276 | 
             
            static size_t ZSTD_compressBlock_fast_extDict_generic(
         | 
| 266 277 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 267 | 
            -
                    void const* src, size_t srcSize,
         | 
| 268 | 
            -
                    U32 const hlog, U32 stepSize, U32 const mls)
         | 
| 278 | 
            +
                    void const* src, size_t srcSize, U32 const mls)
         | 
| 269 279 | 
             
            {
         | 
| 270 | 
            -
                 | 
| 280 | 
            +
                const ZSTD_compressionParameters* const cParams = &ms->cParams;
         | 
| 281 | 
            +
                U32* const hashTable = ms->hashTable;
         | 
| 282 | 
            +
                U32 const hlog = cParams->hashLog;
         | 
| 283 | 
            +
                /* support stepSize of 0 */
         | 
| 284 | 
            +
                U32 const stepSize = cParams->targetLength + !(cParams->targetLength);
         | 
| 271 285 | 
             
                const BYTE* const base = ms->window.base;
         | 
| 272 286 | 
             
                const BYTE* const dictBase = ms->window.dictBase;
         | 
| 273 287 | 
             
                const BYTE* const istart = (const BYTE*)src;
         | 
| @@ -282,8 +296,6 @@ static size_t ZSTD_compressBlock_fast_extDict_generic( | |
| 282 296 | 
             
                const BYTE* const ilimit = iend - 8;
         | 
| 283 297 | 
             
                U32 offset_1=rep[0], offset_2=rep[1];
         | 
| 284 298 |  | 
| 285 | 
            -
                stepSize += !stepSize;   /* support stepSize == 0 */
         | 
| 286 | 
            -
             | 
| 287 299 | 
             
                /* Search Loop */
         | 
| 288 300 | 
             
                while (ip < ilimit) {  /* < instead of <=, because (ip+1) */
         | 
| 289 301 | 
             
                    const size_t h = ZSTD_hashPtr(ip, hlog, mls);
         | 
| @@ -360,21 +372,20 @@ static size_t ZSTD_compressBlock_fast_extDict_generic( | |
| 360 372 |  | 
| 361 373 | 
             
            size_t ZSTD_compressBlock_fast_extDict(
         | 
| 362 374 | 
             
                    ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
         | 
| 363 | 
            -
                     | 
| 375 | 
            +
                    void const* src, size_t srcSize)
         | 
| 364 376 | 
             
            {
         | 
| 365 | 
            -
                 | 
| 377 | 
            +
                ZSTD_compressionParameters const* cParams = &ms->cParams;
         | 
| 366 378 | 
             
                U32 const mls = cParams->searchLength;
         | 
| 367 | 
            -
                U32 const stepSize = cParams->targetLength;
         | 
| 368 379 | 
             
                switch(mls)
         | 
| 369 380 | 
             
                {
         | 
| 370 381 | 
             
                default: /* includes case 3 */
         | 
| 371 382 | 
             
                case 4 :
         | 
| 372 | 
            -
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize,  | 
| 383 | 
            +
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 4);
         | 
| 373 384 | 
             
                case 5 :
         | 
| 374 | 
            -
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize,  | 
| 385 | 
            +
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 5);
         | 
| 375 386 | 
             
                case 6 :
         | 
| 376 | 
            -
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize,  | 
| 387 | 
            +
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 6);
         | 
| 377 388 | 
             
                case 7 :
         | 
| 378 | 
            -
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize,  | 
| 389 | 
            +
                    return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 7);
         | 
| 379 390 | 
             
                }
         | 
| 380 391 | 
             
            }
         |