com.wallstop-studios.unity-helpers 2.0.0-rc79.3 → 2.0.0-rc79.5

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.
Files changed (48) hide show
  1. package/.github/dependabot.yml +5 -1
  2. package/.github/workflows/npm-publish.yml +2 -2
  3. package/Runtime/Core/Extension/IReadonlyListExtensions.cs +1 -1
  4. package/Runtime/Core/Extension/IReadonlyListExtensions.cs.meta +1 -1
  5. package/Runtime/Core/Extension/StringExtensions.cs +1 -1
  6. package/Runtime/Core/Helper/StringInList.cs +3 -21
  7. package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +157 -49
  8. package/Runtime/Utils/Buffers.cs +118 -2
  9. package/Runtime/Utils/SevenZip/Common/CRC.cs +9 -0
  10. package/Runtime/Utils/SevenZip/Common/InBuffer.cs +15 -2
  11. package/Runtime/Utils/SevenZip/Common/OutBuffer.cs +7 -2
  12. package/Runtime/Utils/SevenZip/Compress/LZ/LzBinTree.cs +50 -0
  13. package/Runtime/Utils/SevenZip/Compress/LZ/LzInWindow.cs +26 -0
  14. package/Runtime/Utils/SevenZip/Compress/LZ/LzOutWindow.cs +27 -0
  15. package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaBase.cs +9 -0
  16. package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaDecoder.cs +80 -17
  17. package/Runtime/Utils/SevenZip/Compress/LZMA/LzmaEncoder.cs +265 -30
  18. package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoder.cs +9 -0
  19. package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBit.cs +13 -1
  20. package/Runtime/Utils/SevenZip/Compress/RangeCoder/RangeCoderBitTree.cs +11 -4
  21. package/Tests/Runtime/Core/Threading/SingleThreadedThreadPoolTests.cs +54 -0
  22. package/Tests/Runtime/Core/Threading/SingleThreadedThreadPoolTests.cs.meta +3 -0
  23. package/Tests/Runtime/Core/Threading.meta +3 -0
  24. package/Tests/Runtime/Core.meta +3 -0
  25. package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +1 -1
  26. package/Tests/Runtime/DataStructures/CyclicBufferTests.cs +1 -1
  27. package/Tests/Runtime/DataStructures/QuadTreeTests.cs +1 -1
  28. package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +1 -1
  29. package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +1 -1
  30. package/Tests/Runtime/Extensions/DictionaryExtensionTests.cs +1 -1
  31. package/Tests/Runtime/Extensions/EnumExtensionTests.cs +1 -1
  32. package/Tests/Runtime/Extensions/IListExtensionTests.cs +1 -1
  33. package/Tests/Runtime/Extensions/IReadonlyListExtensionTests.cs +1 -1
  34. package/Tests/Runtime/Extensions/IReadonlyListExtensionTests.cs.meta +1 -1
  35. package/Tests/Runtime/Extensions/LoggingExtensionTests.cs +1 -1
  36. package/Tests/Runtime/Extensions/RandomExtensionTests.cs +1 -1
  37. package/Tests/Runtime/Extensions/StringExtensionTests.cs +1 -1
  38. package/Tests/Runtime/Helper/ObjectHelperTests.cs +1 -1
  39. package/Tests/Runtime/Helper/WallMathTests.cs +1 -1
  40. package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +1 -1
  41. package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +1 -1
  42. package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +1 -2
  43. package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +1 -1
  44. package/Tests/Runtime/Random/RandomTestBase.cs +2 -2
  45. package/Tests/Runtime/Serialization/JsonSerializationTest.cs +1 -1
  46. package/Tests/Runtime/Utils/BuffersTests.cs +55 -0
  47. package/Tests/Runtime/Utils/BuffersTests.cs.meta +3 -0
  48. package/package.json +3 -1
@@ -62,7 +62,10 @@ namespace SevenZip.Compression.LZ
62
62
  {
63
63
  base.Init();
64
64
  for (UInt32 i = 0; i < _hashSizeSum; i++)
65
+ {
65
66
  _hash[i] = kEmptyHashValue;
67
+ }
68
+
66
69
  _cyclicBufferPos = 0;
67
70
  ReduceOffsets(-1);
68
71
  }
@@ -70,10 +73,15 @@ namespace SevenZip.Compression.LZ
70
73
  public new void MovePos()
71
74
  {
72
75
  if (++_cyclicBufferPos >= _cyclicBufferSize)
76
+ {
73
77
  _cyclicBufferPos = 0;
78
+ }
79
+
74
80
  base.MovePos();
75
81
  if (_pos == kMaxValForNormalize)
82
+ {
76
83
  Normalize();
84
+ }
77
85
  }
78
86
 
79
87
  public new Byte GetIndexByte(Int32 index)
@@ -99,7 +107,10 @@ namespace SevenZip.Compression.LZ
99
107
  )
100
108
  {
101
109
  if (historySize > kMaxValForNormalize - 256)
110
+ {
102
111
  throw new Exception();
112
+ }
113
+
103
114
  _cutValue = 16 + (matchMaxLen >> 1);
104
115
 
105
116
  UInt32 windowReservSize =
@@ -115,7 +126,9 @@ namespace SevenZip.Compression.LZ
115
126
 
116
127
  UInt32 cyclicBufferSize = historySize + 1;
117
128
  if (_cyclicBufferSize != cyclicBufferSize)
129
+ {
118
130
  _son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];
131
+ }
119
132
 
120
133
  UInt32 hs = kBT2HashSize;
121
134
 
@@ -129,20 +142,27 @@ namespace SevenZip.Compression.LZ
129
142
  hs >>= 1;
130
143
  hs |= 0xFFFF;
131
144
  if (hs > (1 << 24))
145
+ {
132
146
  hs >>= 1;
147
+ }
148
+
133
149
  _hashMask = hs;
134
150
  hs++;
135
151
  hs += kFixHashSize;
136
152
  }
137
153
  if (hs != _hashSizeSum)
154
+ {
138
155
  _hash = new UInt32[_hashSizeSum = hs];
156
+ }
139
157
  }
140
158
 
141
159
  public UInt32 GetMatches(UInt32[] distances)
142
160
  {
143
161
  UInt32 lenLimit;
144
162
  if (_pos + _matchMaxLen <= _streamPos)
163
+ {
145
164
  lenLimit = _matchMaxLen;
165
+ }
146
166
  else
147
167
  {
148
168
  lenLimit = _streamPos - _pos;
@@ -170,7 +190,9 @@ namespace SevenZip.Compression.LZ
170
190
  hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
171
191
  }
172
192
  else
193
+ {
173
194
  hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
195
+ }
174
196
 
175
197
  UInt32 curMatch = _hash[kFixHashSize + hashValue];
176
198
  if (HASH_ARRAY)
@@ -180,20 +202,29 @@ namespace SevenZip.Compression.LZ
180
202
  _hash[hash2Value] = _pos;
181
203
  _hash[kHash3Offset + hash3Value] = _pos;
182
204
  if (curMatch2 > matchMinPos)
205
+ {
183
206
  if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
184
207
  {
185
208
  distances[offset++] = maxLen = 2;
186
209
  distances[offset++] = _pos - curMatch2 - 1;
187
210
  }
211
+ }
212
+
188
213
  if (curMatch3 > matchMinPos)
214
+ {
189
215
  if (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])
190
216
  {
191
217
  if (curMatch3 == curMatch2)
218
+ {
192
219
  offset -= 2;
220
+ }
221
+
193
222
  distances[offset++] = maxLen = 3;
194
223
  distances[offset++] = _pos - curMatch3 - 1;
195
224
  curMatch2 = curMatch3;
196
225
  }
226
+ }
227
+
197
228
  if (offset != 0 && curMatch2 == curMatch)
198
229
  {
199
230
  offset -= 2;
@@ -247,8 +278,13 @@ namespace SevenZip.Compression.LZ
247
278
  if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
248
279
  {
249
280
  while (++len != lenLimit)
281
+ {
250
282
  if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
283
+ {
251
284
  break;
285
+ }
286
+ }
287
+
252
288
  if (maxLen < len)
253
289
  {
254
290
  distances[offset++] = maxLen = len;
@@ -286,7 +322,9 @@ namespace SevenZip.Compression.LZ
286
322
  {
287
323
  UInt32 lenLimit;
288
324
  if (_pos + _matchMaxLen <= _streamPos)
325
+ {
289
326
  lenLimit = _matchMaxLen;
327
+ }
290
328
  else
291
329
  {
292
330
  lenLimit = _streamPos - _pos;
@@ -313,7 +351,9 @@ namespace SevenZip.Compression.LZ
313
351
  hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
314
352
  }
315
353
  else
354
+ {
316
355
  hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
356
+ }
317
357
 
318
358
  UInt32 curMatch = _hash[kFixHashSize + hashValue];
319
359
  _hash[kFixHashSize + hashValue] = _pos;
@@ -347,8 +387,13 @@ namespace SevenZip.Compression.LZ
347
387
  if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
348
388
  {
349
389
  while (++len != lenLimit)
390
+ {
350
391
  if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
392
+ {
351
393
  break;
394
+ }
395
+ }
396
+
352
397
  if (len == lenLimit)
353
398
  {
354
399
  _son[ptr1] = _son[cyclicPos];
@@ -381,9 +426,14 @@ namespace SevenZip.Compression.LZ
381
426
  {
382
427
  UInt32 value = items[i];
383
428
  if (value <= subValue)
429
+ {
384
430
  value = kEmptyHashValue;
431
+ }
385
432
  else
433
+ {
386
434
  value -= subValue;
435
+ }
436
+
387
437
  items[i] = value;
388
438
  }
389
439
  }
@@ -26,25 +26,36 @@ namespace SevenZip.Compression.LZ
26
26
  UInt32 offset = (UInt32)(_bufferOffset) + _pos - _keepSizeBefore;
27
27
  // we need one additional byte, since MovePos moves on 1 byte.
28
28
  if (offset > 0)
29
+ {
29
30
  offset--;
31
+ }
30
32
 
31
33
  UInt32 numBytes = (UInt32)(_bufferOffset) + _streamPos - offset;
32
34
 
33
35
  // check negative offset ????
34
36
  for (UInt32 i = 0; i < numBytes; i++)
37
+ {
35
38
  _bufferBase[i] = _bufferBase[offset + i];
39
+ }
40
+
36
41
  _bufferOffset -= offset;
37
42
  }
38
43
 
39
44
  public virtual void ReadBlock()
40
45
  {
41
46
  if (_streamEndWasReached)
47
+ {
42
48
  return;
49
+ }
50
+
43
51
  while (true)
44
52
  {
45
53
  int size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);
46
54
  if (size == 0)
55
+ {
47
56
  return;
57
+ }
58
+
48
59
  int numReadBytes = _stream.Read(
49
60
  _bufferBase,
50
61
  (int)(_bufferOffset + _streamPos),
@@ -55,14 +66,18 @@ namespace SevenZip.Compression.LZ
55
66
  _posLimit = _streamPos;
56
67
  UInt32 pointerToPostion = _bufferOffset + _posLimit;
57
68
  if (pointerToPostion > _pointerToLastSafePosition)
69
+ {
58
70
  _posLimit = (UInt32)(_pointerToLastSafePosition - _bufferOffset);
71
+ }
59
72
 
60
73
  _streamEndWasReached = true;
61
74
  return;
62
75
  }
63
76
  _streamPos += (UInt32)numReadBytes;
64
77
  if (_streamPos >= _pos + _keepSizeAfter)
78
+ {
65
79
  _posLimit = _streamPos - _keepSizeAfter;
80
+ }
66
81
  }
67
82
  }
68
83
 
@@ -111,7 +126,10 @@ namespace SevenZip.Compression.LZ
111
126
  {
112
127
  UInt32 pointerToPostion = _bufferOffset + _pos;
113
128
  if (pointerToPostion > _pointerToLastSafePosition)
129
+ {
114
130
  MoveBlock();
131
+ }
132
+
115
133
  ReadBlock();
116
134
  }
117
135
  }
@@ -125,15 +143,23 @@ namespace SevenZip.Compression.LZ
125
143
  public UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)
126
144
  {
127
145
  if (_streamEndWasReached)
146
+ {
128
147
  if ((_pos + index) + limit > _streamPos)
148
+ {
129
149
  limit = _streamPos - (UInt32)(_pos + index);
150
+ }
151
+ }
152
+
130
153
  distance++;
131
154
  // Byte *pby = _buffer + (size_t)_pos + index;
132
155
  UInt32 pby = _bufferOffset + _pos + (UInt32)index;
133
156
 
134
157
  UInt32 i;
135
158
  for (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++)
159
+ {
136
160
  ;
161
+ }
162
+
137
163
  return i;
138
164
  }
139
165
 
@@ -47,15 +47,23 @@ namespace SevenZip.Compression.LZ
47
47
  {
48
48
  uint curSize = _windowSize - _pos;
49
49
  if (size < curSize)
50
+ {
50
51
  curSize = size;
52
+ }
53
+
51
54
  int numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize);
52
55
  if (numReadBytes == 0)
56
+ {
53
57
  return false;
58
+ }
59
+
54
60
  size -= (uint)numReadBytes;
55
61
  _pos += (uint)numReadBytes;
56
62
  _streamPos += (uint)numReadBytes;
57
63
  if (_pos == _windowSize)
64
+ {
58
65
  _streamPos = _pos = 0;
66
+ }
59
67
  }
60
68
  return true;
61
69
  }
@@ -70,10 +78,16 @@ namespace SevenZip.Compression.LZ
70
78
  {
71
79
  uint size = _pos - _streamPos;
72
80
  if (size == 0)
81
+ {
73
82
  return;
83
+ }
84
+
74
85
  _stream.Write(_buffer, (int)_streamPos, (int)size);
75
86
  if (_pos >= _windowSize)
87
+ {
76
88
  _pos = 0;
89
+ }
90
+
77
91
  _streamPos = _pos;
78
92
  }
79
93
 
@@ -81,14 +95,22 @@ namespace SevenZip.Compression.LZ
81
95
  {
82
96
  uint pos = _pos - distance - 1;
83
97
  if (pos >= _windowSize)
98
+ {
84
99
  pos += _windowSize;
100
+ }
101
+
85
102
  for (; len > 0; len--)
86
103
  {
87
104
  if (pos >= _windowSize)
105
+ {
88
106
  pos = 0;
107
+ }
108
+
89
109
  _buffer[_pos++] = _buffer[pos++];
90
110
  if (_pos >= _windowSize)
111
+ {
91
112
  Flush();
113
+ }
92
114
  }
93
115
  }
94
116
 
@@ -96,14 +118,19 @@ namespace SevenZip.Compression.LZ
96
118
  {
97
119
  _buffer[_pos++] = b;
98
120
  if (_pos >= _windowSize)
121
+ {
99
122
  Flush();
123
+ }
100
124
  }
101
125
 
102
126
  public byte GetByte(uint distance)
103
127
  {
104
128
  uint pos = _pos - distance - 1;
105
129
  if (pos >= _windowSize)
130
+ {
106
131
  pos += _windowSize;
132
+ }
133
+
107
134
  return _buffer[pos];
108
135
  }
109
136
  }
@@ -24,11 +24,17 @@ namespace SevenZip.Compression.LZMA
24
24
  public void UpdateChar()
25
25
  {
26
26
  if (Index < 4)
27
+ {
27
28
  Index = 0;
29
+ }
28
30
  else if (Index < 10)
31
+ {
29
32
  Index -= 3;
33
+ }
30
34
  else
35
+ {
31
36
  Index -= 6;
37
+ }
32
38
  }
33
39
 
34
40
  public void UpdateMatch()
@@ -67,7 +73,10 @@ namespace SevenZip.Compression.LZMA
67
73
  {
68
74
  len -= kMatchMinLen;
69
75
  if (len < kNumLenToPosStates)
76
+ {
70
77
  return len;
78
+ }
79
+
71
80
  return (uint)(kNumLenToPosStates - 1);
72
81
  }
73
82
 
@@ -12,8 +12,8 @@ namespace SevenZip.Compression.LZMA
12
12
  {
13
13
  BitDecoder m_Choice = new BitDecoder();
14
14
  BitDecoder m_Choice2 = new BitDecoder();
15
- BitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];
16
- BitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];
15
+ readonly BitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];
16
+ readonly BitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];
17
17
  BitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);
18
18
  uint m_NumPosStates = 0;
19
19
 
@@ -42,12 +42,16 @@ namespace SevenZip.Compression.LZMA
42
42
  public uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)
43
43
  {
44
44
  if (m_Choice.Decode(rangeDecoder) == 0)
45
+ {
45
46
  return m_LowCoder[posState].Decode(rangeDecoder);
47
+ }
46
48
  else
47
49
  {
48
50
  uint symbol = Base.kNumLowLenSymbols;
49
51
  if (m_Choice2.Decode(rangeDecoder) == 0)
52
+ {
50
53
  symbol += m_MidCoder[posState].Decode(rangeDecoder);
54
+ }
51
55
  else
52
56
  {
53
57
  symbol += Base.kNumMidLenSymbols;
@@ -72,14 +76,18 @@ namespace SevenZip.Compression.LZMA
72
76
  public void Init()
73
77
  {
74
78
  for (int i = 0; i < 0x300; i++)
79
+ {
75
80
  m_Decoders[i].Init();
81
+ }
76
82
  }
77
83
 
78
84
  public byte DecodeNormal(RangeCoder.Decoder rangeDecoder)
79
85
  {
80
86
  uint symbol = 1;
81
- do symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);
82
- while (symbol < 0x100);
87
+ do
88
+ {
89
+ symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);
90
+ } while (symbol < 0x100);
83
91
  return (byte)symbol;
84
92
  }
85
93
 
@@ -95,7 +103,10 @@ namespace SevenZip.Compression.LZMA
95
103
  if (matchBit != bit)
96
104
  {
97
105
  while (symbol < 0x100)
106
+ {
98
107
  symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);
108
+ }
109
+
99
110
  break;
100
111
  }
101
112
  } while (symbol < 0x100);
@@ -111,21 +122,28 @@ namespace SevenZip.Compression.LZMA
111
122
  public void Create(int numPosBits, int numPrevBits)
112
123
  {
113
124
  if (m_Coders != null && m_NumPrevBits == numPrevBits && m_NumPosBits == numPosBits)
125
+ {
114
126
  return;
127
+ }
128
+
115
129
  m_NumPosBits = numPosBits;
116
130
  m_PosMask = ((uint)1 << numPosBits) - 1;
117
131
  m_NumPrevBits = numPrevBits;
118
132
  uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
119
133
  m_Coders = new Decoder2[numStates];
120
134
  for (uint i = 0; i < numStates; i++)
135
+ {
121
136
  m_Coders[i].Create();
137
+ }
122
138
  }
123
139
 
124
140
  public void Init()
125
141
  {
126
142
  uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
127
143
  for (uint i = 0; i < numStates; i++)
144
+ {
128
145
  m_Coders[i].Init();
146
+ }
129
147
  }
130
148
 
131
149
  uint GetState(uint pos, byte prevByte)
@@ -151,31 +169,34 @@ namespace SevenZip.Compression.LZMA
151
169
  }
152
170
  };
153
171
 
154
- LZ.OutWindow m_OutWindow = new LZ.OutWindow();
155
- RangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();
172
+ readonly LZ.OutWindow m_OutWindow = new LZ.OutWindow();
173
+ readonly RangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();
156
174
 
157
- BitDecoder[] m_IsMatchDecoders = new BitDecoder[
175
+ readonly BitDecoder[] m_IsMatchDecoders = new BitDecoder[
158
176
  Base.kNumStates << Base.kNumPosStatesBitsMax
159
177
  ];
160
- BitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];
161
- BitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];
162
- BitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];
163
- BitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];
164
- BitDecoder[] m_IsRep0LongDecoders = new BitDecoder[
178
+
179
+ readonly BitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];
180
+ readonly BitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];
181
+ readonly BitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];
182
+ readonly BitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];
183
+
184
+ readonly BitDecoder[] m_IsRep0LongDecoders = new BitDecoder[
165
185
  Base.kNumStates << Base.kNumPosStatesBitsMax
166
186
  ];
167
187
 
168
- BitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];
169
- BitDecoder[] m_PosDecoders = new BitDecoder[
188
+ readonly BitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];
189
+
190
+ readonly BitDecoder[] m_PosDecoders = new BitDecoder[
170
191
  Base.kNumFullDistances - Base.kEndPosModelIndex
171
192
  ];
172
193
 
173
194
  BitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);
174
195
 
175
- LenDecoder m_LenDecoder = new LenDecoder();
176
- LenDecoder m_RepLenDecoder = new LenDecoder();
196
+ readonly LenDecoder m_LenDecoder = new LenDecoder();
197
+ readonly LenDecoder m_RepLenDecoder = new LenDecoder();
177
198
 
178
- LiteralDecoder m_LiteralDecoder = new LiteralDecoder();
199
+ readonly LiteralDecoder m_LiteralDecoder = new LiteralDecoder();
179
200
 
180
201
  uint m_DictionarySize;
181
202
  uint m_DictionarySizeCheck;
@@ -186,7 +207,9 @@ namespace SevenZip.Compression.LZMA
186
207
  {
187
208
  m_DictionarySize = 0xFFFFFFFF;
188
209
  for (int i = 0; i < Base.kNumLenToPosStates; i++)
210
+ {
189
211
  m_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);
212
+ }
190
213
  }
191
214
 
192
215
  void SetDictionarySize(uint dictionarySize)
@@ -203,16 +226,25 @@ namespace SevenZip.Compression.LZMA
203
226
  void SetLiteralProperties(int lp, int lc)
204
227
  {
205
228
  if (lp > 8)
229
+ {
206
230
  throw new InvalidParamException();
231
+ }
232
+
207
233
  if (lc > 8)
234
+ {
208
235
  throw new InvalidParamException();
236
+ }
237
+
209
238
  m_LiteralDecoder.Create(lp, lc);
210
239
  }
211
240
 
212
241
  void SetPosBitsProperties(int pb)
213
242
  {
214
243
  if (pb > Base.kNumPosStatesBitsMax)
244
+ {
215
245
  throw new InvalidParamException();
246
+ }
247
+
216
248
  uint numPosStates = (uint)1 << pb;
217
249
  m_LenDecoder.Create(numPosStates);
218
250
  m_RepLenDecoder.Create(numPosStates);
@@ -243,10 +275,15 @@ namespace SevenZip.Compression.LZMA
243
275
 
244
276
  m_LiteralDecoder.Init();
245
277
  for (i = 0; i < Base.kNumLenToPosStates; i++)
278
+ {
246
279
  m_PosSlotDecoder[i].Init();
280
+ }
281
+
247
282
  // m_PosSpecDecoder.Init();
248
283
  for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)
284
+ {
249
285
  m_PosDecoders[i].Init();
286
+ }
250
287
 
251
288
  m_LenDecoder.Init();
252
289
  m_RepLenDecoder.Init();
@@ -278,7 +315,10 @@ namespace SevenZip.Compression.LZMA
278
315
  m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax]
279
316
  .Decode(m_RangeDecoder) != 0
280
317
  )
318
+ {
281
319
  throw new DataErrorException();
320
+ }
321
+
282
322
  state.UpdateChar();
283
323
  byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);
284
324
  m_OutWindow.PutByte(b);
@@ -298,18 +338,23 @@ namespace SevenZip.Compression.LZMA
298
338
  byte b;
299
339
  byte prevByte = m_OutWindow.GetByte(0);
300
340
  if (!state.IsCharState())
341
+ {
301
342
  b = m_LiteralDecoder.DecodeWithMatchByte(
302
343
  m_RangeDecoder,
303
344
  (uint)nowPos64,
304
345
  prevByte,
305
346
  m_OutWindow.GetByte(rep0)
306
347
  );
348
+ }
307
349
  else
350
+ {
308
351
  b = m_LiteralDecoder.DecodeNormal(
309
352
  m_RangeDecoder,
310
353
  (uint)nowPos64,
311
354
  prevByte
312
355
  );
356
+ }
357
+
313
358
  m_OutWindow.PutByte(b);
314
359
  state.UpdateChar();
315
360
  nowPos64++;
@@ -344,7 +389,9 @@ namespace SevenZip.Compression.LZMA
344
389
  else
345
390
  {
346
391
  if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)
392
+ {
347
393
  distance = rep2;
394
+ }
348
395
  else
349
396
  {
350
397
  distance = rep3;
@@ -374,12 +421,14 @@ namespace SevenZip.Compression.LZMA
374
421
  int numDirectBits = (int)((posSlot >> 1) - 1);
375
422
  rep0 = ((2 | (posSlot & 1)) << numDirectBits);
376
423
  if (posSlot < Base.kEndPosModelIndex)
424
+ {
377
425
  rep0 += BitTreeDecoder.ReverseDecode(
378
426
  m_PosDecoders,
379
427
  rep0 - posSlot - 1,
380
428
  m_RangeDecoder,
381
429
  numDirectBits
382
430
  );
431
+ }
383
432
  else
384
433
  {
385
434
  rep0 += (
@@ -391,7 +440,9 @@ namespace SevenZip.Compression.LZMA
391
440
  }
392
441
  }
393
442
  else
443
+ {
394
444
  rep0 = posSlot;
445
+ }
395
446
  }
396
447
  if (
397
448
  rep0 >= m_OutWindow.TrainSize + nowPos64
@@ -399,7 +450,10 @@ namespace SevenZip.Compression.LZMA
399
450
  )
400
451
  {
401
452
  if (rep0 == 0xFFFFFFFF)
453
+ {
402
454
  break;
455
+ }
456
+
403
457
  throw new DataErrorException();
404
458
  }
405
459
  m_OutWindow.CopyBlock(rep0, len);
@@ -415,16 +469,25 @@ namespace SevenZip.Compression.LZMA
415
469
  public void SetDecoderProperties(byte[] properties)
416
470
  {
417
471
  if (properties.Length < 5)
472
+ {
418
473
  throw new InvalidParamException();
474
+ }
475
+
419
476
  int lc = properties[0] % 9;
420
477
  int remainder = properties[0] / 9;
421
478
  int lp = remainder % 5;
422
479
  int pb = remainder / 5;
423
480
  if (pb > Base.kNumPosStatesBitsMax)
481
+ {
424
482
  throw new InvalidParamException();
483
+ }
484
+
425
485
  UInt32 dictionarySize = 0;
426
486
  for (int i = 0; i < 4; i++)
487
+ {
427
488
  dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
489
+ }
490
+
428
491
  SetDictionarySize(dictionarySize);
429
492
  SetLiteralProperties(lp, lc);
430
493
  SetPosBitsProperties(pb);