lib/generic-radix-tree: Simplify offset calculation:
Subsystems (2)
PATCH 10/13 lib/generic-radix-tree: Simplify offset calculation:
Since these are equivalent:
(idx / objs_per_page) * PAGE_SIZE + (idx % objs_per_page) * obj_size;
idx * obj_size + (idx / objs_per_page) * (PAGE_SIZE % obj_size);Use the latter since it is slightly faster.
It also deosn't need an extra check for obj_size being a power of 2.
Signed-off-by David Laight <[email protected]>
--- include/linux/generic-radix-tree.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
include/linux/generic-radix-tree.h +2 -7
@@ -100,14 +100,9 @@ void __genradix_free(struct __genradix *);static inline size_t __idx_to_offset (size_t idx,size_t obj_size) { -if (!is_power_of_2 (obj_size)) { -size_t objs_per_page =PAGE_SIZE / obj_size; +size_t objs_per_page =PAGE_SIZE / obj_size; -return (idx / objs_per_page) *PAGE_SIZE + - (idx % objs_per_page) * obj_size; - }else { -return idx * obj_size; - } +return idx * obj_size + (idx / objs_per_page) * (PAGE_SIZE % obj_size); }#define __genradix_cast (_radix) (typeof((_radix)->type[0]) *)
Signature · 5 lines
2.25.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)