Commit 29c336af authored by Joshua Ashton's avatar Joshua Ashton Committed by Kent Overstreet
Browse files

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: default avatarJoshua Ashton <joshua@froggi.es>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 01a7e74f
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment