Message ID | 8b986d23bf05684ae37102993b406e4e582dec39.1676991868.git.anand.jain@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] btrfs: make btrfs_bin_search a macro | expand |
On Tue, Feb 21, 2023 at 11:09:30PM +0800, Anand Jain wrote: > btrfs_bin_search() is an inline function that wraps > btrfs_generic_bin_search() and sets the second argument to 0. > > The inline compiler directive is not always guaranteed to work, > unless the __always_inline directive is used. > > Further, this function is small and can be a #define macro as well. > Make btrfs_bin_search() a macro. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > v2: remove extra ; for define > > fs/btrfs/ctree.h | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h > index 97897107fab5..1e1b8f4992a3 100644 > --- a/fs/btrfs/ctree.h > +++ b/fs/btrfs/ctree.h > @@ -515,15 +515,9 @@ int btrfs_generic_bin_search(struct extent_buffer *eb, int first_slot, > * Simple binary search on an extent buffer. Works for both leaves and nodes, and > * always searches over the whole range of keys (slot 0 to slot 'nritems - 1'). > */ > -static inline int btrfs_bin_search(struct extent_buffer *eb, > - const struct btrfs_key *key, > - int *slot) > -{ > - return btrfs_generic_bin_search(eb, 0, key, slot); > -} > +#define btrfs_bin_search(eb, key, slot) \ > + btrfs_generic_bin_search(eb, 0, key, slot) > > -int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, > - int *slot); I don't see much reason to do that, the static inline defined in a header works as expected and is inlined where used and then it's up to the compiler to decide if it'll be combined, partitoned or optimized in other ways. We don't need such a simple wrapper if the only difference is the added start offset so you can keep btrfs_bin_search and add the same parameters as btrfs_generic_bin_search has now. > int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); > int btrfs_previous_item(struct btrfs_root *root, > struct btrfs_path *path, u64 min_objectid, > -- > 2.38.1
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 97897107fab5..1e1b8f4992a3 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -515,15 +515,9 @@ int btrfs_generic_bin_search(struct extent_buffer *eb, int first_slot, * Simple binary search on an extent buffer. Works for both leaves and nodes, and * always searches over the whole range of keys (slot 0 to slot 'nritems - 1'). */ -static inline int btrfs_bin_search(struct extent_buffer *eb, - const struct btrfs_key *key, - int *slot) -{ - return btrfs_generic_bin_search(eb, 0, key, slot); -} +#define btrfs_bin_search(eb, key, slot) \ + btrfs_generic_bin_search(eb, 0, key, slot) -int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key, - int *slot); int __pure btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2); int btrfs_previous_item(struct btrfs_root *root, struct btrfs_path *path, u64 min_objectid,
btrfs_bin_search() is an inline function that wraps btrfs_generic_bin_search() and sets the second argument to 0. The inline compiler directive is not always guaranteed to work, unless the __always_inline directive is used. Further, this function is small and can be a #define macro as well. Make btrfs_bin_search() a macro. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- v2: remove extra ; for define fs/btrfs/ctree.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)