File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -283,17 +283,28 @@ bool RLT::inverse(SliceArray<kanzi::byte>& input, SliceArray<kanzi::byte>& outpu
283283
284284 // Main loop
285285 while (srcIdx < srcEnd) {
286- if (src[srcIdx] != escape) {
287- // Literal
288- if (dstIdx >= dstEnd) {
286+ // Copy a span of literals in one operation. Escaped literals are
287+ // encoded as escape, 0, so the first escape always terminates the
288+ // current literal span.
289+ const byte* const esc = static_cast <const byte*>(
290+ std::memchr (&src[srcIdx], int (uint8 (escape)), size_t (srcEnd - srcIdx)));
291+ const int literalLen = (esc == nullptr ) ? (srcEnd - srcIdx) : int (esc - &src[srcIdx]);
292+
293+ if (literalLen > 0 ) {
294+ if (literalLen > dstEnd - dstIdx) {
289295 res = false ;
290296 break ;
291297 }
292298
293- dst[dstIdx++] = src[srcIdx++];
294- continue ;
299+ std::memcpy (&dst[dstIdx], &src[srcIdx], size_t (literalLen));
300+ srcIdx += literalLen;
301+ dstIdx += literalLen;
295302 }
296303
304+ if (srcIdx >= srcEnd)
305+ break ;
306+
307+ // An escape marker was found
297308 srcIdx++;
298309
299310 if (srcIdx >= srcEnd) {
You can’t perform that action at this time.
0 commit comments