History

lib: rework bitmap_parse()

bitmap_parse() is ineffective and full of opaque variables and opencoded parts. It leads to hard understanding and usage of it. This rework includes: - remove bitmap_shift_left() call from the cycle. Now it makes the complexity of the algorithm as O(nbits^2). In the suggested approach the input string is parsed in reverse direction, so no shifts needed; - relax requirement on a single comma and no white spaces between chunks. It is considered useful in scripting, and it aligns with bitmap_parselist(); - split bitmap_parse() to small readable helpers; - make an explicit calculation of the end of input line at the beginning, so users of the bitmap_parse() won't bother doing this.

Yury Norov committed 6 years ago

Commit 2d626151 parent e66eda02 files · +84 −99Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/bitmap.h+1−7
@@ -186,7 +186,7 @@ bitmap_find_next_zero_area(unsigned long *map, · 185 unmodified lines
186 align_mask, 0);186 align_mask, 0);
187}187}
188 188
189extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user,189extern int bitmap_parse(const char *buf, unsigned int buflen,
190 unsigned long *dst, int nbits);190 unsigned long *dst, int nbits);
191extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,191extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
192 unsigned long *dst, int nbits);192 unsigned long *dst, int nbits);
@@ -454,12 +454,6 @@ static inline void bitmap_replace(unsigned long *dst, · 261 unmodified lines
454 __bitmap_replace(dst, old, new, mask, nbits);454 __bitmap_replace(dst, old, new, mask, nbits);
455}455}
456 456
457static inline int bitmap_parse(const char *buf, unsigned int buflen,
458 unsigned long *maskp, int nmaskbits)
459{
460 return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
461}
462
463static inline void bitmap_next_clear_region(unsigned long *bitmap,457static inline void bitmap_next_clear_region(unsigned long *bitmap,
464 unsigned int *rs, unsigned int *re,458 unsigned int *rs, unsigned int *re,
465 unsigned int end)459 unsigned int end)