Skip to content

Commit 72fc4ad

Browse files
improving comments
1 parent 9711ed8 commit 72fc4ad

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/decompress/lzss.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ LZSSDecoder::status LZSSDecoder::handle_state() {
216216
case FSM_1:
217217
putc(c);
218218
buffer[r++] = c;
219-
r &= (N - 1); // equivalent to r = r % N
219+
r &= (N - 1); // equivalent to r = r % N when N is a power of 2
220220

221221
this->state = FSM_0;
222222
break;
@@ -226,10 +226,16 @@ LZSSDecoder::status LZSSDecoder::handle_state() {
226226
break;
227227
case FSM_3: {
228228
int j = c;
229-
for (int k = 0; k <= j + 1; k++) { // TODO improve by using memcpy
230-
c = buffer[(this->i + k) & (N - 1)]; // equivalent to buffer[(i+k) % N]
229+
230+
// This is where the actual decompression takes place: we look into the local buffer for reuse
231+
// of byte chunks. This can be improved by means of memcpy and by changing the putc function
232+
// into a put_buf function in order to avoid buffering on the other end.
233+
// TODO improve this section of code
234+
for (int k = 0; k <= j + 1; k++) {
235+
c = buffer[(this->i + k) & (N - 1)]; // equivalent to buffer[(i+k) % N] when N is a power of 2
231236
putc(c);
232-
buffer[r++] = c; r &= (N - 1); // equivalent to r = r % N
237+
buffer[r++] = c;
238+
r &= (N - 1); // equivalent to r = r % N
233239
}
234240
this->state = FSM_0;
235241

0 commit comments

Comments
 (0)