]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
swab.c(libc): use a simplified version of byte swapping
authorrilysh <nightquick@proton.me>
Mon, 22 Apr 2024 21:52:25 +0000 (15:52 -0600)
committerWarner Losh <imp@FreeBSD.org>
Tue, 23 Apr 2024 05:01:54 +0000 (23:01 -0600)
commitbac2eea13ae3e4dc8fd2aec261b2a18930138495
treef591d76bd20838d06c7abc7059c5afdde001201e
parentf578d0199761136e82850d8f086b8806f2dbad8d
swab.c(libc): use a simplified version of byte swapping

This version of swab function simplifies the logic of swapping adjacent
bytes. Previous version of swab() used an arbitrary unrolling, which was
relevant back in the day but unnecessary for modern compilers, as if the
input size is known at compile time, they can do it automatically.

This version of swab() is inspired by musl.
A similar version can be found at: https://github.com/openbsd/src/blob/master/lib/libc/string/swab.c

Signed-off-by: rilysh <nightquick@proton.me>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1086
lib/libc/string/swab.c