Message ID | 91753cb284a2dbce72e5b5b31b658e1c50ef084e.1582832619.git.dsterba@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Misc cleanups | expand |
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
On 2020/2/28 上午4:00, David Sterba wrote: > There's an unnecessary indirection in the checksum definition table, > pointer and the string itself. The strings are short and the overall > size of one entry is now 24 bytes. > > Signed-off-by: David Sterba <dsterba@suse.com> > --- > fs/btrfs/ctree.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c > index f948435e87df..bfedbbe2311f 100644 > --- a/fs/btrfs/ctree.c > +++ b/fs/btrfs/ctree.c > @@ -31,8 +31,8 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, > > static const struct btrfs_csums { > u16 size; > - const char *name; > - const char *driver; > + const char name[10]; Just a nitpick, the longest name I haven seen is "xxhash64" which is only 8 chars, +1 for '\n'. Thus we can save one extra byte here. Despite that. Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > + const char driver[12]; > } btrfs_csums[] = { > [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" }, > [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" }, > @@ -63,7 +63,8 @@ const char *btrfs_super_csum_name(u16 csum_type) > const char *btrfs_super_csum_driver(u16 csum_type) > { > /* csum type is validated at mount time */ > - return btrfs_csums[csum_type].driver ?: > + return btrfs_csums[csum_type].driver[0] ? > + btrfs_csums[csum_type].driver : > btrfs_csums[csum_type].name; > } > >
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index f948435e87df..bfedbbe2311f 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -31,8 +31,8 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, static const struct btrfs_csums { u16 size; - const char *name; - const char *driver; + const char name[10]; + const char driver[12]; } btrfs_csums[] = { [BTRFS_CSUM_TYPE_CRC32] = { .size = 4, .name = "crc32c" }, [BTRFS_CSUM_TYPE_XXHASH] = { .size = 8, .name = "xxhash64" }, @@ -63,7 +63,8 @@ const char *btrfs_super_csum_name(u16 csum_type) const char *btrfs_super_csum_driver(u16 csum_type) { /* csum type is validated at mount time */ - return btrfs_csums[csum_type].driver ?: + return btrfs_csums[csum_type].driver[0] ? + btrfs_csums[csum_type].driver : btrfs_csums[csum_type].name; }
There's an unnecessary indirection in the checksum definition table, pointer and the string itself. The strings are short and the overall size of one entry is now 24 bytes. Signed-off-by: David Sterba <dsterba@suse.com> --- fs/btrfs/ctree.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)