Skip to content

Commit 54db7b9

Browse files
committed
btrfs: accessors: use type sizeof constants directly
Now unit_size is used only once, so use it directly in 'part' calculation. Don't cache sizeof(type) in a variable. While this is a compile-time constant, forcing the type 'int' generates worse code as it leads to additional conversion from 32 to 64 bit type on x86_64. The sizeof() is used only a few times and it does not make the code that harder to read, so use it directly and let the compiler utilize the immediate constants in the context it needs. The .ko code size slightly increases (+50) but further patches will reduce that again. Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a16c62c commit 54db7b9

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

fs/btrfs/accessors.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
5252
const unsigned long idx = get_eb_folio_index(eb, member_offset);\
5353
const unsigned long oil = get_eb_offset_in_folio(eb, \
5454
member_offset);\
55-
const int unit_size = eb->folio_size; \
5655
char *kaddr = folio_address(eb->folios[idx]); \
57-
const int size = sizeof(u##bits); \
58-
const int part = unit_size - oil; \
56+
const int part = eb->folio_size - oil; \
5957
u8 lebytes[sizeof(u##bits)]; \
6058
\
61-
ASSERT(check_setget_bounds(eb, ptr, off, size)); \
59+
ASSERT(check_setget_bounds(eb, ptr, off, sizeof(u##bits))); \
6260
if (INLINE_EXTENT_BUFFER_PAGES == 1 || likely(sizeof(u##bits) <= part)) \
6361
return get_unaligned_le##bits(kaddr + oil); \
6462
\
6563
memcpy(lebytes, kaddr + oil, part); \
6664
kaddr = folio_address(eb->folios[idx + 1]); \
67-
memcpy(lebytes + part, kaddr, size - part); \
65+
memcpy(lebytes + part, kaddr, sizeof(u##bits) - part); \
6866
return get_unaligned_le##bits(lebytes); \
6967
} \
7068
void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
@@ -74,13 +72,11 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
7472
const unsigned long idx = get_eb_folio_index(eb, member_offset);\
7573
const unsigned long oil = get_eb_offset_in_folio(eb, \
7674
member_offset);\
77-
const int unit_size = eb->folio_size; \
7875
char *kaddr = folio_address(eb->folios[idx]); \
79-
const int size = sizeof(u##bits); \
80-
const int part = unit_size - oil; \
76+
const int part = eb->folio_size - oil; \
8177
u8 lebytes[sizeof(u##bits)]; \
8278
\
83-
ASSERT(check_setget_bounds(eb, ptr, off, size)); \
79+
ASSERT(check_setget_bounds(eb, ptr, off, sizeof(u##bits))); \
8480
if (INLINE_EXTENT_BUFFER_PAGES == 1 || \
8581
likely(sizeof(u##bits) <= part)) { \
8682
put_unaligned_le##bits(val, kaddr + oil); \
@@ -90,7 +86,7 @@ void btrfs_set_##bits(const struct extent_buffer *eb, void *ptr, \
9086
put_unaligned_le##bits(val, lebytes); \
9187
memcpy(kaddr + oil, lebytes, part); \
9288
kaddr = folio_address(eb->folios[idx + 1]); \
93-
memcpy(kaddr, lebytes + part, size - part); \
89+
memcpy(kaddr, lebytes + part, sizeof(u##bits) - part); \
9490
}
9591

9692
DEFINE_BTRFS_SETGET_BITS(8)

0 commit comments

Comments
 (0)