Skip to content

Commit cc267ee

Browse files
committed
Speed optimization
1 parent 2599777 commit cc267ee

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/transform/ROLZCodec.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,24 @@ namespace kanzi {
289289

290290
inline int ROLZCodec::emitCopy(byte buf[], int dstIdx, int ref, int matchLen)
291291
{
292-
if (dstIdx >= ref + matchLen) {
293-
memcpy(&buf[dstIdx], &buf[ref], size_t(matchLen));
294-
return dstIdx + matchLen;
292+
const int res = dstIdx + matchLen;
293+
294+
if (dstIdx - ref >= 8) {
295+
while (matchLen > 0) {
296+
memcpy(&buf[dstIdx], &buf[ref], 8);
297+
ref += 8;
298+
dstIdx += 8;
299+
matchLen -= 8;
300+
}
295301
}
296-
297-
while (matchLen != 0) {
298-
buf[dstIdx++] = buf[ref++];
299-
matchLen--;
302+
else {
303+
while (matchLen != 0) {
304+
buf[dstIdx++] = buf[ref++];
305+
matchLen--;
306+
}
300307
}
301308

302-
return dstIdx;
309+
return res;
303310
}
304311

305312
inline void ROLZEncoder::encodeBit(int bit)

0 commit comments

Comments
 (0)