Skip to content

Commit e5bda3d

Browse files
committed
Cosmetic changes
1 parent c926893 commit e5bda3d

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/transform/ROLZCodec.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ bool ROLZCodec1::forward(SliceArray<byte>& input, SliceArray<byte>& output, int
295295

296296
// token LLLLLMMM -> L lit length, M match length
297297
const int litLen = srcIdx - firstLitIdx;
298-
const int token = (litLen < 31) ? (litLen << 3) : 0xF8;
298+
const int token = (litLen < 31) ? litLen << 3 : 0xF8;
299299
const int mLen = match & 0xFFFF;
300300

301301
if (mLen >= 7) {
@@ -308,9 +308,7 @@ bool ROLZCodec1::forward(SliceArray<byte>& input, SliceArray<byte>& output, int
308308

309309
// Emit literals
310310
if (litLen > 0) {
311-
if (litLen >= 31)
312-
lenBuf._index += emitLength(&lenBuf._array[lenBuf._index], litLen - 31);
313-
311+
lenBuf._index += (litLen >= 31 ? emitLength(&lenBuf._array[lenBuf._index], litLen - 31) : 0);
314312
memcpy(&litBuf._array[litBuf._index], &buf[firstLitIdx], size_t(litLen));
315313
litBuf._index += litLen;
316314
}
@@ -323,18 +321,15 @@ bool ROLZCodec1::forward(SliceArray<byte>& input, SliceArray<byte>& output, int
323321
}
324322

325323
// Emit last chunk literals
326-
srcIdx = sizeChunk;
327-
const int litLen = srcIdx - firstLitIdx;
324+
const int litLen = sizeChunk - firstLitIdx;
328325

329326
if (tkBuf._index != 0) {
330327
// At least one match to emit
331-
const int token = (litLen < 31) ? (litLen << 3) : 0xF8;
328+
const int token = (litLen < 31) ? litLen << 3 : 0xF8;
332329
tkBuf._array[tkBuf._index++] = byte(token);
333330
}
334331

335-
if (litLen >= 31)
336-
lenBuf._index += emitLength(&lenBuf._array[lenBuf._index], litLen - 31);
337-
332+
lenBuf._index += (litLen >= 31 ? emitLength(&lenBuf._array[lenBuf._index], litLen - 31) : 0);
338333
memcpy(&litBuf._array[litBuf._index], &buf[firstLitIdx], size_t(litLen));
339334
litBuf._index += litLen;
340335

@@ -530,10 +525,8 @@ bool ROLZCodec1::inverse(SliceArray<byte>& input, SliceArray<byte>& output, int
530525
while (dstIdx < sizeChunk) {
531526
// token LLLLLMMM -> L lit length, M match length
532527
const int token = int(tkBuf._array[tkBuf._index++]);
533-
int matchLen = token & 0x07;
534-
535-
if (matchLen == 7)
536-
matchLen += readLength(lenBuf._array, lenBuf._index);
528+
int mLen = token & 0x07;
529+
mLen += (mLen == 7 ? _minMatch + readLength(lenBuf._array, lenBuf._index) : _minMatch);
537530

538531
// Emit literals
539532
const int litLen = (token < 0xF8) ? token >> 3 : readLength(lenBuf._array, lenBuf._index) + 31;
@@ -585,18 +578,18 @@ bool ROLZCodec1::inverse(SliceArray<byte>& input, SliceArray<byte>& output, int
585578
}
586579

587580
// Sanity check
588-
if (output._index + dstIdx + matchLen + _minMatch > dstEnd) {
581+
if (output._index + dstIdx + mLen > dstEnd) {
589582
success = false;
590583
goto End;
591584
}
592585

593-
const uint8 matchIdx = uint8(mIdxBuf._array[mIdxBuf._index++]);
586+
const uint8 mIdx = uint8(mIdxBuf._array[mIdxBuf._index++]);
594587
const uint32 key = (cond == true) ? ROLZCodec::getKey1(&refBuf[dstIdx]) : ROLZCodec::getKey2(&refBuf[dstIdx]);
595588
uint32* matches = &_matches[key << _logPosChecks];
596-
const int32 ref = matches[(_counters[key] - matchIdx) & _maskChecks];
589+
const int32 ref = matches[(_counters[key] - mIdx) & _maskChecks];
597590
_counters[key] = (_counters[key] + 1) & _maskChecks;
598591
matches[_counters[key]] = dstIdx;
599-
dstIdx = ROLZCodec::emitCopy(buf, dstIdx, ref, matchLen + _minMatch);
592+
dstIdx = ROLZCodec::emitCopy(buf, dstIdx, ref, mLen);
600593
}
601594

602595
startChunk = endChunk;

0 commit comments

Comments
 (0)