zstd-ruby 1.3.0.0 → 1.3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/zstdruby/libzstd/common/bitstream.h +40 -41
  4. data/ext/zstdruby/libzstd/common/compiler.h +85 -0
  5. data/ext/zstdruby/libzstd/common/error_private.c +8 -10
  6. data/ext/zstdruby/libzstd/common/error_private.h +4 -4
  7. data/ext/zstdruby/libzstd/common/fse.h +11 -5
  8. data/ext/zstdruby/libzstd/common/fse_decompress.c +3 -22
  9. data/ext/zstdruby/libzstd/common/huf.h +5 -6
  10. data/ext/zstdruby/libzstd/common/mem.h +6 -6
  11. data/ext/zstdruby/libzstd/common/pool.c +61 -27
  12. data/ext/zstdruby/libzstd/common/pool.h +10 -10
  13. data/ext/zstdruby/libzstd/common/threading.h +5 -6
  14. data/ext/zstdruby/libzstd/common/xxhash.c +28 -22
  15. data/ext/zstdruby/libzstd/common/zstd_common.c +4 -4
  16. data/ext/zstdruby/libzstd/common/zstd_errors.h +30 -32
  17. data/ext/zstdruby/libzstd/common/zstd_internal.h +57 -56
  18. data/ext/zstdruby/libzstd/compress/fse_compress.c +4 -22
  19. data/ext/zstdruby/libzstd/compress/huf_compress.c +4 -3
  20. data/ext/zstdruby/libzstd/compress/zstd_compress.c +314 -304
  21. data/ext/zstdruby/libzstd/compress/zstd_opt.h +118 -116
  22. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +223 -156
  23. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +10 -9
  24. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +8 -24
  25. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +95 -115
  26. data/ext/zstdruby/libzstd/deprecated/zbuff.h +4 -4
  27. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +4 -5
  28. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +4 -4
  29. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +4 -4
  30. data/ext/zstdruby/libzstd/dictBuilder/cover.c +7 -9
  31. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +5 -5
  32. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +4 -4
  33. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +8 -4
  34. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +4 -4
  35. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +4 -4
  36. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +4 -4
  37. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +4 -4
  38. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +4 -4
  39. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +4 -4
  40. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +5 -5
  41. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +4 -4
  42. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +5 -5
  43. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +4 -4
  44. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +5 -5
  45. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +4 -4
  46. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +4 -4
  47. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +4 -4
  48. data/ext/zstdruby/libzstd/zstd.h +16 -14
  49. data/lib/zstd-ruby/version.rb +1 -1
  50. metadata +3 -2
@@ -1,10 +1,10 @@
1
- /**
2
- * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
1
+ /*
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
8
  */
9
9
 
10
10
 
@@ -22,173 +22,173 @@
22
22
  /*-*************************************
23
23
  * Price functions for optimal parser
24
24
  ***************************************/
25
- FORCE_INLINE void ZSTD_setLog2Prices(seqStore_t* ssPtr)
25
+ static void ZSTD_setLog2Prices(optState_t* optPtr)
26
26
  {
27
- ssPtr->log2matchLengthSum = ZSTD_highbit32(ssPtr->matchLengthSum+1);
28
- ssPtr->log2litLengthSum = ZSTD_highbit32(ssPtr->litLengthSum+1);
29
- ssPtr->log2litSum = ZSTD_highbit32(ssPtr->litSum+1);
30
- ssPtr->log2offCodeSum = ZSTD_highbit32(ssPtr->offCodeSum+1);
31
- ssPtr->factor = 1 + ((ssPtr->litSum>>5) / ssPtr->litLengthSum) + ((ssPtr->litSum<<1) / (ssPtr->litSum + ssPtr->matchSum));
27
+ optPtr->log2matchLengthSum = ZSTD_highbit32(optPtr->matchLengthSum+1);
28
+ optPtr->log2litLengthSum = ZSTD_highbit32(optPtr->litLengthSum+1);
29
+ optPtr->log2litSum = ZSTD_highbit32(optPtr->litSum+1);
30
+ optPtr->log2offCodeSum = ZSTD_highbit32(optPtr->offCodeSum+1);
31
+ optPtr->factor = 1 + ((optPtr->litSum>>5) / optPtr->litLengthSum) + ((optPtr->litSum<<1) / (optPtr->litSum + optPtr->matchSum));
32
32
  }
33
33
 
34
34
 
35
- MEM_STATIC void ZSTD_rescaleFreqs(seqStore_t* ssPtr, const BYTE* src, size_t srcSize)
35
+ static void ZSTD_rescaleFreqs(optState_t* optPtr, const BYTE* src, size_t srcSize)
36
36
  {
37
37
  unsigned u;
38
38
 
39
- ssPtr->cachedLiterals = NULL;
40
- ssPtr->cachedPrice = ssPtr->cachedLitLength = 0;
41
- ssPtr->staticPrices = 0;
39
+ optPtr->cachedLiterals = NULL;
40
+ optPtr->cachedPrice = optPtr->cachedLitLength = 0;
41
+ optPtr->staticPrices = 0;
42
42
 
43
- if (ssPtr->litLengthSum == 0) {
44
- if (srcSize <= 1024) ssPtr->staticPrices = 1;
43
+ if (optPtr->litLengthSum == 0) {
44
+ if (srcSize <= 1024) optPtr->staticPrices = 1;
45
45
 
46
- assert(ssPtr->litFreq!=NULL);
46
+ assert(optPtr->litFreq!=NULL);
47
47
  for (u=0; u<=MaxLit; u++)
48
- ssPtr->litFreq[u] = 0;
48
+ optPtr->litFreq[u] = 0;
49
49
  for (u=0; u<srcSize; u++)
50
- ssPtr->litFreq[src[u]]++;
50
+ optPtr->litFreq[src[u]]++;
51
51
 
52
- ssPtr->litSum = 0;
53
- ssPtr->litLengthSum = MaxLL+1;
54
- ssPtr->matchLengthSum = MaxML+1;
55
- ssPtr->offCodeSum = (MaxOff+1);
56
- ssPtr->matchSum = (ZSTD_LITFREQ_ADD<<Litbits);
52
+ optPtr->litSum = 0;
53
+ optPtr->litLengthSum = MaxLL+1;
54
+ optPtr->matchLengthSum = MaxML+1;
55
+ optPtr->offCodeSum = (MaxOff+1);
56
+ optPtr->matchSum = (ZSTD_LITFREQ_ADD<<Litbits);
57
57
 
58
58
  for (u=0; u<=MaxLit; u++) {
59
- ssPtr->litFreq[u] = 1 + (ssPtr->litFreq[u]>>ZSTD_FREQ_DIV);
60
- ssPtr->litSum += ssPtr->litFreq[u];
59
+ optPtr->litFreq[u] = 1 + (optPtr->litFreq[u]>>ZSTD_FREQ_DIV);
60
+ optPtr->litSum += optPtr->litFreq[u];
61
61
  }
62
62
  for (u=0; u<=MaxLL; u++)
63
- ssPtr->litLengthFreq[u] = 1;
63
+ optPtr->litLengthFreq[u] = 1;
64
64
  for (u=0; u<=MaxML; u++)
65
- ssPtr->matchLengthFreq[u] = 1;
65
+ optPtr->matchLengthFreq[u] = 1;
66
66
  for (u=0; u<=MaxOff; u++)
67
- ssPtr->offCodeFreq[u] = 1;
67
+ optPtr->offCodeFreq[u] = 1;
68
68
  } else {
69
- ssPtr->matchLengthSum = 0;
70
- ssPtr->litLengthSum = 0;
71
- ssPtr->offCodeSum = 0;
72
- ssPtr->matchSum = 0;
73
- ssPtr->litSum = 0;
69
+ optPtr->matchLengthSum = 0;
70
+ optPtr->litLengthSum = 0;
71
+ optPtr->offCodeSum = 0;
72
+ optPtr->matchSum = 0;
73
+ optPtr->litSum = 0;
74
74
 
75
75
  for (u=0; u<=MaxLit; u++) {
76
- ssPtr->litFreq[u] = 1 + (ssPtr->litFreq[u]>>(ZSTD_FREQ_DIV+1));
77
- ssPtr->litSum += ssPtr->litFreq[u];
76
+ optPtr->litFreq[u] = 1 + (optPtr->litFreq[u]>>(ZSTD_FREQ_DIV+1));
77
+ optPtr->litSum += optPtr->litFreq[u];
78
78
  }
79
79
  for (u=0; u<=MaxLL; u++) {
80
- ssPtr->litLengthFreq[u] = 1 + (ssPtr->litLengthFreq[u]>>(ZSTD_FREQ_DIV+1));
81
- ssPtr->litLengthSum += ssPtr->litLengthFreq[u];
80
+ optPtr->litLengthFreq[u] = 1 + (optPtr->litLengthFreq[u]>>(ZSTD_FREQ_DIV+1));
81
+ optPtr->litLengthSum += optPtr->litLengthFreq[u];
82
82
  }
83
83
  for (u=0; u<=MaxML; u++) {
84
- ssPtr->matchLengthFreq[u] = 1 + (ssPtr->matchLengthFreq[u]>>ZSTD_FREQ_DIV);
85
- ssPtr->matchLengthSum += ssPtr->matchLengthFreq[u];
86
- ssPtr->matchSum += ssPtr->matchLengthFreq[u] * (u + 3);
84
+ optPtr->matchLengthFreq[u] = 1 + (optPtr->matchLengthFreq[u]>>ZSTD_FREQ_DIV);
85
+ optPtr->matchLengthSum += optPtr->matchLengthFreq[u];
86
+ optPtr->matchSum += optPtr->matchLengthFreq[u] * (u + 3);
87
87
  }
88
- ssPtr->matchSum *= ZSTD_LITFREQ_ADD;
88
+ optPtr->matchSum *= ZSTD_LITFREQ_ADD;
89
89
  for (u=0; u<=MaxOff; u++) {
90
- ssPtr->offCodeFreq[u] = 1 + (ssPtr->offCodeFreq[u]>>ZSTD_FREQ_DIV);
91
- ssPtr->offCodeSum += ssPtr->offCodeFreq[u];
90
+ optPtr->offCodeFreq[u] = 1 + (optPtr->offCodeFreq[u]>>ZSTD_FREQ_DIV);
91
+ optPtr->offCodeSum += optPtr->offCodeFreq[u];
92
92
  }
93
93
  }
94
94
 
95
- ZSTD_setLog2Prices(ssPtr);
95
+ ZSTD_setLog2Prices(optPtr);
96
96
  }
97
97
 
98
98
 
99
- FORCE_INLINE U32 ZSTD_getLiteralPrice(seqStore_t* ssPtr, U32 litLength, const BYTE* literals)
99
+ static U32 ZSTD_getLiteralPrice(optState_t* optPtr, U32 litLength, const BYTE* literals)
100
100
  {
101
101
  U32 price, u;
102
102
 
103
- if (ssPtr->staticPrices)
103
+ if (optPtr->staticPrices)
104
104
  return ZSTD_highbit32((U32)litLength+1) + (litLength*6);
105
105
 
106
106
  if (litLength == 0)
107
- return ssPtr->log2litLengthSum - ZSTD_highbit32(ssPtr->litLengthFreq[0]+1);
107
+ return optPtr->log2litLengthSum - ZSTD_highbit32(optPtr->litLengthFreq[0]+1);
108
108
 
109
109
  /* literals */
110
- if (ssPtr->cachedLiterals == literals) {
111
- U32 const additional = litLength - ssPtr->cachedLitLength;
112
- const BYTE* literals2 = ssPtr->cachedLiterals + ssPtr->cachedLitLength;
113
- price = ssPtr->cachedPrice + additional * ssPtr->log2litSum;
110
+ if (optPtr->cachedLiterals == literals) {
111
+ U32 const additional = litLength - optPtr->cachedLitLength;
112
+ const BYTE* literals2 = optPtr->cachedLiterals + optPtr->cachedLitLength;
113
+ price = optPtr->cachedPrice + additional * optPtr->log2litSum;
114
114
  for (u=0; u < additional; u++)
115
- price -= ZSTD_highbit32(ssPtr->litFreq[literals2[u]]+1);
116
- ssPtr->cachedPrice = price;
117
- ssPtr->cachedLitLength = litLength;
115
+ price -= ZSTD_highbit32(optPtr->litFreq[literals2[u]]+1);
116
+ optPtr->cachedPrice = price;
117
+ optPtr->cachedLitLength = litLength;
118
118
  } else {
119
- price = litLength * ssPtr->log2litSum;
119
+ price = litLength * optPtr->log2litSum;
120
120
  for (u=0; u < litLength; u++)
121
- price -= ZSTD_highbit32(ssPtr->litFreq[literals[u]]+1);
121
+ price -= ZSTD_highbit32(optPtr->litFreq[literals[u]]+1);
122
122
 
123
123
  if (litLength >= 12) {
124
- ssPtr->cachedLiterals = literals;
125
- ssPtr->cachedPrice = price;
126
- ssPtr->cachedLitLength = litLength;
124
+ optPtr->cachedLiterals = literals;
125
+ optPtr->cachedPrice = price;
126
+ optPtr->cachedLitLength = litLength;
127
127
  }
128
128
  }
129
129
 
130
130
  /* literal Length */
131
131
  { const BYTE LL_deltaCode = 19;
132
132
  const BYTE llCode = (litLength>63) ? (BYTE)ZSTD_highbit32(litLength) + LL_deltaCode : LL_Code[litLength];
133
- price += LL_bits[llCode] + ssPtr->log2litLengthSum - ZSTD_highbit32(ssPtr->litLengthFreq[llCode]+1);
133
+ price += LL_bits[llCode] + optPtr->log2litLengthSum - ZSTD_highbit32(optPtr->litLengthFreq[llCode]+1);
134
134
  }
135
135
 
136
136
  return price;
137
137
  }
138
138
 
139
139
 
140
- FORCE_INLINE U32 ZSTD_getPrice(seqStore_t* seqStorePtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength, const int ultra)
140
+ FORCE_INLINE_TEMPLATE U32 ZSTD_getPrice(optState_t* optPtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength, const int ultra)
141
141
  {
142
142
  /* offset */
143
143
  U32 price;
144
144
  BYTE const offCode = (BYTE)ZSTD_highbit32(offset+1);
145
145
 
146
- if (seqStorePtr->staticPrices)
147
- return ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + ZSTD_highbit32((U32)matchLength+1) + 16 + offCode;
146
+ if (optPtr->staticPrices)
147
+ return ZSTD_getLiteralPrice(optPtr, litLength, literals) + ZSTD_highbit32((U32)matchLength+1) + 16 + offCode;
148
148
 
149
- price = offCode + seqStorePtr->log2offCodeSum - ZSTD_highbit32(seqStorePtr->offCodeFreq[offCode]+1);
149
+ price = offCode + optPtr->log2offCodeSum - ZSTD_highbit32(optPtr->offCodeFreq[offCode]+1);
150
150
  if (!ultra && offCode >= 20) price += (offCode-19)*2;
151
151
 
152
152
  /* match Length */
153
153
  { const BYTE ML_deltaCode = 36;
154
154
  const BYTE mlCode = (matchLength>127) ? (BYTE)ZSTD_highbit32(matchLength) + ML_deltaCode : ML_Code[matchLength];
155
- price += ML_bits[mlCode] + seqStorePtr->log2matchLengthSum - ZSTD_highbit32(seqStorePtr->matchLengthFreq[mlCode]+1);
155
+ price += ML_bits[mlCode] + optPtr->log2matchLengthSum - ZSTD_highbit32(optPtr->matchLengthFreq[mlCode]+1);
156
156
  }
157
157
 
158
- return price + ZSTD_getLiteralPrice(seqStorePtr, litLength, literals) + seqStorePtr->factor;
158
+ return price + ZSTD_getLiteralPrice(optPtr, litLength, literals) + optPtr->factor;
159
159
  }
160
160
 
161
161
 
162
- MEM_STATIC void ZSTD_updatePrice(seqStore_t* seqStorePtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength)
162
+ static void ZSTD_updatePrice(optState_t* optPtr, U32 litLength, const BYTE* literals, U32 offset, U32 matchLength)
163
163
  {
164
164
  U32 u;
165
165
 
166
166
  /* literals */
167
- seqStorePtr->litSum += litLength*ZSTD_LITFREQ_ADD;
167
+ optPtr->litSum += litLength*ZSTD_LITFREQ_ADD;
168
168
  for (u=0; u < litLength; u++)
169
- seqStorePtr->litFreq[literals[u]] += ZSTD_LITFREQ_ADD;
169
+ optPtr->litFreq[literals[u]] += ZSTD_LITFREQ_ADD;
170
170
 
171
171
  /* literal Length */
172
172
  { const BYTE LL_deltaCode = 19;
173
173
  const BYTE llCode = (litLength>63) ? (BYTE)ZSTD_highbit32(litLength) + LL_deltaCode : LL_Code[litLength];
174
- seqStorePtr->litLengthFreq[llCode]++;
175
- seqStorePtr->litLengthSum++;
174
+ optPtr->litLengthFreq[llCode]++;
175
+ optPtr->litLengthSum++;
176
176
  }
177
177
 
178
178
  /* match offset */
179
179
  { BYTE const offCode = (BYTE)ZSTD_highbit32(offset+1);
180
- seqStorePtr->offCodeSum++;
181
- seqStorePtr->offCodeFreq[offCode]++;
180
+ optPtr->offCodeSum++;
181
+ optPtr->offCodeFreq[offCode]++;
182
182
  }
183
183
 
184
184
  /* match Length */
185
185
  { const BYTE ML_deltaCode = 36;
186
186
  const BYTE mlCode = (matchLength>127) ? (BYTE)ZSTD_highbit32(matchLength) + ML_deltaCode : ML_Code[matchLength];
187
- seqStorePtr->matchLengthFreq[mlCode]++;
188
- seqStorePtr->matchLengthSum++;
187
+ optPtr->matchLengthFreq[mlCode]++;
188
+ optPtr->matchLengthSum++;
189
189
  }
190
190
 
191
- ZSTD_setLog2Prices(seqStorePtr);
191
+ ZSTD_setLog2Prices(optPtr);
192
192
  }
193
193
 
194
194
 
@@ -203,7 +203,7 @@ MEM_STATIC void ZSTD_updatePrice(seqStore_t* seqStorePtr, U32 litLength, const B
203
203
 
204
204
 
205
205
  /* function safe only for comparisons */
206
- MEM_STATIC U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
206
+ static U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
207
207
  {
208
208
  switch (length)
209
209
  {
@@ -219,7 +219,7 @@ MEM_STATIC U32 ZSTD_readMINMATCH(const void* memPtr, U32 length)
219
219
 
220
220
  /* Update hashTable3 up to ip (excluded)
221
221
  Assumption : always within prefix (i.e. not within extDict) */
222
- FORCE_INLINE
222
+ static
223
223
  U32 ZSTD_insertAndFindFirstIndexHash3 (ZSTD_CCtx* zc, const BYTE* ip)
224
224
  {
225
225
  U32* const hashTable3 = zc->hashTable3;
@@ -412,11 +412,12 @@ static U32 ZSTD_BtGetAllMatches_selectMLS_extDict (
412
412
  /*-*******************************
413
413
  * Optimal parser
414
414
  *********************************/
415
- FORCE_INLINE
415
+ FORCE_INLINE_TEMPLATE
416
416
  void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
417
417
  const void* src, size_t srcSize, const int ultra)
418
418
  {
419
419
  seqStore_t* seqStorePtr = &(ctx->seqStore);
420
+ optState_t* optStatePtr = &(ctx->optState);
420
421
  const BYTE* const istart = (const BYTE*)src;
421
422
  const BYTE* ip = istart;
422
423
  const BYTE* anchor = istart;
@@ -430,16 +431,16 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
430
431
  const U32 mls = ctx->appliedParams.cParams.searchLength;
431
432
  const U32 minMatch = (ctx->appliedParams.cParams.searchLength == 3) ? 3 : 4;
432
433
 
433
- ZSTD_optimal_t* opt = seqStorePtr->priceTable;
434
- ZSTD_match_t* matches = seqStorePtr->matchTable;
434
+ ZSTD_optimal_t* opt = optStatePtr->priceTable;
435
+ ZSTD_match_t* matches = optStatePtr->matchTable;
435
436
  const BYTE* inr;
436
437
  U32 offset, rep[ZSTD_REP_NUM];
437
438
 
438
439
  /* init */
439
440
  ctx->nextToUpdate3 = ctx->nextToUpdate;
440
- ZSTD_rescaleFreqs(seqStorePtr, (const BYTE*)src, srcSize);
441
+ ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize);
441
442
  ip += (ip==prefixStart);
442
- { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=ctx->rep[i]; }
443
+ { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=seqStorePtr->rep[i]; }
443
444
 
444
445
  /* Match Loop */
445
446
  while (ip < ilimit) {
@@ -462,7 +463,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
462
463
  }
463
464
  best_off = i - (ip == anchor);
464
465
  do {
465
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
466
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
466
467
  if (mlen > last_pos || price < opt[mlen].price)
467
468
  SET_PRICE(mlen, mlen, i, litlen, price); /* note : macro modifies last_pos */
468
469
  mlen--;
@@ -487,7 +488,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
487
488
  mlen = (u>0) ? matches[u-1].len+1 : best_mlen;
488
489
  best_mlen = matches[u].len;
489
490
  while (mlen <= best_mlen) {
490
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
491
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
491
492
  if (mlen > last_pos || price < opt[mlen].price)
492
493
  SET_PRICE(mlen, mlen, matches[u].off, litlen, price); /* note : macro modifies last_pos */
493
494
  mlen++;
@@ -507,12 +508,12 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
507
508
  if (opt[cur-1].mlen == 1) {
508
509
  litlen = opt[cur-1].litlen + 1;
509
510
  if (cur > litlen) {
510
- price = opt[cur - litlen].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr-litlen);
511
+ price = opt[cur - litlen].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-litlen);
511
512
  } else
512
- price = ZSTD_getLiteralPrice(seqStorePtr, litlen, anchor);
513
+ price = ZSTD_getLiteralPrice(optStatePtr, litlen, anchor);
513
514
  } else {
514
515
  litlen = 1;
515
- price = opt[cur - 1].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr-1);
516
+ price = opt[cur - 1].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-1);
516
517
  }
517
518
 
518
519
  if (cur > last_pos || price <= opt[cur].price)
@@ -554,12 +555,12 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
554
555
  if (opt[cur].mlen == 1) {
555
556
  litlen = opt[cur].litlen;
556
557
  if (cur > litlen) {
557
- price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, best_off, mlen - MINMATCH, ultra);
558
+ price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, inr-litlen, best_off, mlen - MINMATCH, ultra);
558
559
  } else
559
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
560
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
560
561
  } else {
561
562
  litlen = 0;
562
- price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
563
+ price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
563
564
  }
564
565
 
565
566
  if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
@@ -586,12 +587,12 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
586
587
  if (opt[cur].mlen == 1) {
587
588
  litlen = opt[cur].litlen;
588
589
  if (cur > litlen)
589
- price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, ip+cur-litlen, matches[u].off-1, mlen - MINMATCH, ultra);
590
+ price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, ip+cur-litlen, matches[u].off-1, mlen - MINMATCH, ultra);
590
591
  else
591
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
592
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
592
593
  } else {
593
594
  litlen = 0;
594
- price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, matches[u].off-1, mlen - MINMATCH, ultra);
595
+ price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, matches[u].off-1, mlen - MINMATCH, ultra);
595
596
  }
596
597
 
597
598
  if (cur + mlen > last_pos || (price < opt[cur + mlen].price))
@@ -645,13 +646,13 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
645
646
  if (litLength==0) offset--;
646
647
  }
647
648
 
648
- ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH);
649
+ ZSTD_updatePrice(optStatePtr, litLength, anchor, offset, mlen-MINMATCH);
649
650
  ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH);
650
651
  anchor = ip = ip + mlen;
651
652
  } } /* for (cur=0; cur < last_pos; ) */
652
653
 
653
654
  /* Save reps for next block */
654
- { int i; for (i=0; i<ZSTD_REP_NUM; i++) ctx->repToConfirm[i] = rep[i]; }
655
+ { int i; for (i=0; i<ZSTD_REP_NUM; i++) seqStorePtr->repToConfirm[i] = rep[i]; }
655
656
 
656
657
  /* Last Literals */
657
658
  { size_t const lastLLSize = iend - anchor;
@@ -661,11 +662,12 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
661
662
  }
662
663
 
663
664
 
664
- FORCE_INLINE
665
+ FORCE_INLINE_TEMPLATE
665
666
  void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
666
667
  const void* src, size_t srcSize, const int ultra)
667
668
  {
668
669
  seqStore_t* seqStorePtr = &(ctx->seqStore);
670
+ optState_t* optStatePtr = &(ctx->optState);
669
671
  const BYTE* const istart = (const BYTE*)src;
670
672
  const BYTE* ip = istart;
671
673
  const BYTE* anchor = istart;
@@ -683,16 +685,16 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
683
685
  const U32 mls = ctx->appliedParams.cParams.searchLength;
684
686
  const U32 minMatch = (ctx->appliedParams.cParams.searchLength == 3) ? 3 : 4;
685
687
 
686
- ZSTD_optimal_t* opt = seqStorePtr->priceTable;
687
- ZSTD_match_t* matches = seqStorePtr->matchTable;
688
+ ZSTD_optimal_t* opt = optStatePtr->priceTable;
689
+ ZSTD_match_t* matches = optStatePtr->matchTable;
688
690
  const BYTE* inr;
689
691
 
690
692
  /* init */
691
693
  U32 offset, rep[ZSTD_REP_NUM];
692
- { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=ctx->rep[i]; }
694
+ { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=seqStorePtr->rep[i]; }
693
695
 
694
696
  ctx->nextToUpdate3 = ctx->nextToUpdate;
695
- ZSTD_rescaleFreqs(seqStorePtr, (const BYTE*)src, srcSize);
697
+ ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize);
696
698
  ip += (ip==prefixStart);
697
699
 
698
700
  /* Match Loop */
@@ -726,7 +728,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
726
728
  best_off = i - (ip==anchor);
727
729
  litlen = opt[0].litlen;
728
730
  do {
729
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
731
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
730
732
  if (mlen > last_pos || price < opt[mlen].price)
731
733
  SET_PRICE(mlen, mlen, i, litlen, price); /* note : macro modifies last_pos */
732
734
  mlen--;
@@ -756,7 +758,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
756
758
  best_mlen = matches[u].len;
757
759
  litlen = opt[0].litlen;
758
760
  while (mlen <= best_mlen) {
759
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
761
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
760
762
  if (mlen > last_pos || price < opt[mlen].price)
761
763
  SET_PRICE(mlen, mlen, matches[u].off, litlen, price);
762
764
  mlen++;
@@ -773,12 +775,12 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
773
775
  if (opt[cur-1].mlen == 1) {
774
776
  litlen = opt[cur-1].litlen + 1;
775
777
  if (cur > litlen) {
776
- price = opt[cur - litlen].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr-litlen);
778
+ price = opt[cur - litlen].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-litlen);
777
779
  } else
778
- price = ZSTD_getLiteralPrice(seqStorePtr, litlen, anchor);
780
+ price = ZSTD_getLiteralPrice(optStatePtr, litlen, anchor);
779
781
  } else {
780
782
  litlen = 1;
781
- price = opt[cur - 1].price + ZSTD_getLiteralPrice(seqStorePtr, litlen, inr-1);
783
+ price = opt[cur - 1].price + ZSTD_getLiteralPrice(optStatePtr, litlen, inr-1);
782
784
  }
783
785
 
784
786
  if (cur > last_pos || price <= opt[cur].price)
@@ -826,12 +828,12 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
826
828
  if (opt[cur].mlen == 1) {
827
829
  litlen = opt[cur].litlen;
828
830
  if (cur > litlen) {
829
- price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, best_off, mlen - MINMATCH, ultra);
831
+ price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, inr-litlen, best_off, mlen - MINMATCH, ultra);
830
832
  } else
831
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
833
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, best_off, mlen - MINMATCH, ultra);
832
834
  } else {
833
835
  litlen = 0;
834
- price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
836
+ price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, best_off, mlen - MINMATCH, ultra);
835
837
  }
836
838
 
837
839
  if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
@@ -858,12 +860,12 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
858
860
  if (opt[cur].mlen == 1) {
859
861
  litlen = opt[cur].litlen;
860
862
  if (cur > litlen)
861
- price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, ip+cur-litlen, matches[u].off-1, mlen - MINMATCH, ultra);
863
+ price = opt[cur - litlen].price + ZSTD_getPrice(optStatePtr, litlen, ip+cur-litlen, matches[u].off-1, mlen - MINMATCH, ultra);
862
864
  else
863
- price = ZSTD_getPrice(seqStorePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
865
+ price = ZSTD_getPrice(optStatePtr, litlen, anchor, matches[u].off-1, mlen - MINMATCH, ultra);
864
866
  } else {
865
867
  litlen = 0;
866
- price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, matches[u].off-1, mlen - MINMATCH, ultra);
868
+ price = opt[cur].price + ZSTD_getPrice(optStatePtr, 0, NULL, matches[u].off-1, mlen - MINMATCH, ultra);
867
869
  }
868
870
 
869
871
  if (cur + mlen > last_pos || (price < opt[cur + mlen].price))
@@ -918,13 +920,13 @@ _storeSequence: /* cur, last_pos, best_mlen, best_off have to be set */
918
920
  if (litLength==0) offset--;
919
921
  }
920
922
 
921
- ZSTD_updatePrice(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH);
923
+ ZSTD_updatePrice(optStatePtr, litLength, anchor, offset, mlen-MINMATCH);
922
924
  ZSTD_storeSeq(seqStorePtr, litLength, anchor, offset, mlen-MINMATCH);
923
925
  anchor = ip = ip + mlen;
924
926
  } } /* for (cur=0; cur < last_pos; ) */
925
927
 
926
928
  /* Save reps for next block */
927
- { int i; for (i=0; i<ZSTD_REP_NUM; i++) ctx->repToConfirm[i] = rep[i]; }
929
+ { int i; for (i=0; i<ZSTD_REP_NUM; i++) seqStorePtr->repToConfirm[i] = rep[i]; }
928
930
 
929
931
  /* Last Literals */
930
932
  { size_t lastLLSize = iend - anchor;