bcachefs: Optimize bch2_dirent_name_bytes
authorJoshua Ashton <joshua@froggi.es>
Sat, 12 Aug 2023 21:26:30 +0000 (22:26 +0100)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:10 +0000 (17:10 -0400)
commit29c336afebb9013706334c1b451f31fe5ff37f34
treef554c506062f017438625969e2ff08b98b0d30e1
parent01a7e74fe14179cba90bf3f52ad3188a1d6819d2
bcachefs: Optimize bch2_dirent_name_bytes

Avoids doing a full strnlen for getting the length of the name of a
dirent entry.

Given the fact that the name of dirents is stored at the end of the
bkey's value, and we know the length of that in u64s, we can find the
last u64 and figure out how many NUL bytes are at the end of the string.

On little endian systems this ends up being the leading zeros of the
last u64, whereas on big endian systems this ends up being the trailing
zeros of the last u64.
We can take that value in bits and divide it by 8 to get the number of
NUL bytes at the end.

There is no endian-fixup or other compatibility here as this is string
data interpreted as a u64.

Signed-off-by: Joshua Ashton <joshua@froggi.es>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/dirent.c