Re: [PATCH 2/3] lib: zlib_inflate: improves decompression performance

From: Zhaoxiu Zeng
Date: Wed Nov 11 2020 - 11:07:23 EST


在 2020/11/11 11:46, Jann Horn 写道:
> On Mon, Nov 9, 2020 at 8:27 PM <zengzhaoxiu@xxxxxxx> wrote:
>> This patch does:
>> 1. Cleanup code and reduce branches
>> 2. Use copy_from_back to copy the matched bytes from the back output buffer
>
> What exactly is copy_from_back()? Is it like memmove()? If yes, have
> you tried using memmove() instead of the code added in patch 1/3?
>

If use memcpy(or memmove), the code will be like this:
while (dist < len) {
memcpy(out, out - dist, dist);
out += dist;
len -= dist;
}
memcpy(out, out - dist, len);
or:
const u8 * const from = out - dist;
while (dist < len) {
memcpy(out, from, dist);
out += dist;
len -= dist;
dist *= 2;
}
memcpy(out, from, len);

In addition, the len is small in most cases, so the function calls are expensive.