]> git.kaiwu.me - haproxy.git/commit
MINOR: tools: add memcpy_opt_small() for ultra-small copies
authorWilly Tarreau <w@1wt.eu>
Tue, 24 Nov 2026 08:46:37 +0000 (08:46 +0000)
committerWilly Tarreau <w@1wt.eu>
Tue, 24 Nov 2026 09:50:37 +0000 (10:50 +0100)
commit8ee28984452ca81d8727d71b842d08e3d870082f
treefe449d2a2fd89c89d4b8d938898af0a78eb37e0e
parent7bbeca1e8e61631c662b45152abd259f07fc7638
MINOR: tools: add memcpy_opt_small() for ultra-small copies

Some parsers need to copy many tiny objects of variable size (e.g. HTTP/1
chunks of a few bytes), for which calling the libc's memcpy() costs much
more than the copy itself, because the compiler cannot inline a copy
whose size it does not know.

memcpy_opt_small() copies sizes from 1 to 32 inline after two to four
tests, using at most two possibly overlapping fixed-size copies that the
compiler turns into simple loads and stores: one byte then 2 bytes at the
end for 1 to 3 bytes, then 4, 8 or 16 bytes at each end for 4 to 7, 8 to
16 and 17 to 32 bytes respectively. Larger sizes fall back to memcpy(). A
size of zero is not supported since one byte is always copied.
include/haproxy/tools.h