Patch series "lib: rework bitmap_parse", v5. Similarl to the recently revisited bitmap_parselist(), bitmap_parse() is ineffective and overcomplicated. This series reworks it, aligns its interface with bitmap_parselist() and makes it simpler to use. The series also adds a test for the function and fixes usage of it in cpumask_parse() according to the new design - drops the calculating of length of an input string. bitmap_parse() takes the array of numbers to be put into the map in the BE order which is reversed to the natural LE order for bitmaps. For example, to construct bitmap containing a bit on the position 42, we have to put a line '400,0'. Current implementation reads chunk one by one from the beginning ('400' before '0') and makes bitmap shift after each successful parse. It makes the complexity of the whole process as O(n^2). We can do it in reverse direction ('0' before '400') and avoid shifting, but it requires reverse parsing helpers. This patch (of 7): New function works like strchrnul() with a length limited string.
Showing the changes to lib/string.c (1 of 2 files). Show all
Unified · Split
| @@ -434,6 +434,23 @@ char *strchrnul(const char *s, int c) · 433 unmodified lines | |||
| 434 | EXPORT_SYMBOL(strchrnul); | 434 | EXPORT_SYMBOL(strchrnul); |
| 435 | #endif | 435 | #endif |
| 436 | 436 | ||
| 437 | /** | ||
| 438 | * strnchrnul - Find and return a character in a length limited string, | ||
| 439 | * or end of string | ||
| 440 | * @s: The string to be searched | ||
| 441 | * @count: The number of characters to be searched | ||
| 442 | * @c: The character to search for | ||
| 443 | * | ||
| 444 | * Returns pointer to the first occurrence of 'c' in s. If c is not found, | ||
| 445 | * then return a pointer to the last character of the string. | ||
| 446 | */ | ||
| 447 | char *strnchrnul(const char *s, size_t count, int c) | ||
| 448 | { | ||
| 449 | while (count-- && *s && *s != (char)c) | ||
| 450 | s++; | ||
| 451 | return (char *)s; | ||
| 452 | } | ||
| 453 | |||
| 437 | #ifndef __HAVE_ARCH_STRRCHR | 454 | #ifndef __HAVE_ARCH_STRRCHR |
| 438 | /** | 455 | /** |
| 439 | * strrchr - Find the last occurrence of a character in a string | 456 | * strrchr - Find the last occurrence of a character in a string |