diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-11-24 03:38:31 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:46 -0400 |
commit | 0aba9eba76442d6887dc98924bb8c0396a79c984 (patch) | |
tree | 2b11a9cc936881a251d063ecfaa74d56ca0d07bd /fs/bcachefs/bkey.h | |
parent | a2519a9688d3eeb6c4b2df3ab80b70e62458528d (diff) | |
download | linux-0aba9eba76442d6887dc98924bb8c0396a79c984.tar.gz linux-0aba9eba76442d6887dc98924bb8c0396a79c984.tar.bz2 linux-0aba9eba76442d6887dc98924bb8c0396a79c984.zip |
bcachefs: Inline bch2_bkey_format_add_key()
This is only called in two places, and when it's used we use it in a
tight loop - it's definitely worth inlining.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/bkey.h')
-rw-r--r-- | fs/bcachefs/bkey.h | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h index 137b2d8bdb49..0ce020bcc55f 100644 --- a/fs/bcachefs/bkey.h +++ b/fs/bcachefs/bkey.h @@ -97,17 +97,6 @@ do { \ struct btree; -struct bkey_format_state { - u64 field_min[BKEY_NR_FIELDS]; - u64 field_max[BKEY_NR_FIELDS]; -}; - -void bch2_bkey_format_init(struct bkey_format_state *); -void bch2_bkey_format_add_key(struct bkey_format_state *, const struct bkey *); -void bch2_bkey_format_add_pos(struct bkey_format_state *, struct bpos); -struct bkey_format bch2_bkey_format_done(struct bkey_format_state *); -const char *bch2_bkey_format_validate(struct bkey_format *); - __pure unsigned bch2_bkey_greatest_differing_bit(const struct btree *, const struct bkey_packed *, @@ -671,4 +660,40 @@ void bch2_bkey_pack_test(void); static inline void bch2_bkey_pack_test(void) {} #endif +#define bkey_fields() \ + x(BKEY_FIELD_INODE, p.inode) \ + x(BKEY_FIELD_OFFSET, p.offset) \ + x(BKEY_FIELD_SNAPSHOT, p.snapshot) \ + x(BKEY_FIELD_SIZE, size) \ + x(BKEY_FIELD_VERSION_HI, version.hi) \ + x(BKEY_FIELD_VERSION_LO, version.lo) + +struct bkey_format_state { + u64 field_min[BKEY_NR_FIELDS]; + u64 field_max[BKEY_NR_FIELDS]; +}; + +void bch2_bkey_format_init(struct bkey_format_state *); + +static inline void __bkey_format_add(struct bkey_format_state *s, unsigned field, u64 v) +{ + s->field_min[field] = min(s->field_min[field], v); + s->field_max[field] = max(s->field_max[field], v); +} + +/* + * Changes @format so that @k can be successfully packed with @format + */ +static inline void bch2_bkey_format_add_key(struct bkey_format_state *s, const struct bkey *k) +{ +#define x(id, field) __bkey_format_add(s, id, k->field); + bkey_fields() +#undef x + __bkey_format_add(s, BKEY_FIELD_OFFSET, bkey_start_offset(k)); +} + +void bch2_bkey_format_add_pos(struct bkey_format_state *, struct bpos); +struct bkey_format bch2_bkey_format_done(struct bkey_format_state *); +const char *bch2_bkey_format_validate(struct bkey_format *); + #endif /* _BCACHEFS_BKEY_H */ |