summaryrefslogtreecommitdiffstats
path: root/lib/string.c
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2022-04-29 14:38:01 -0700
committerakpm <akpm@linux-foundation.org>2022-04-29 14:38:01 -0700
commitdffad91b06e0a1ee584f008565cbf2bb508a9777 (patch)
tree6f39e7834212d6093b827e8d2e892ef27513a50b /lib/string.c
parente0fa2ab3fcff42b8c2ed906f5619aae896e1e5e1 (diff)
downloadlinux-stable-dffad91b06e0a1ee584f008565cbf2bb508a9777.tar.gz
linux-stable-dffad91b06e0a1ee584f008565cbf2bb508a9777.tar.bz2
linux-stable-dffad91b06e0a1ee584f008565cbf2bb508a9777.zip
lib/string.c: simplify str[c]spn
Use strchr(), which makes them a lot shorter, and more obviously symmetric in their treatment of accept/reject. It also saves a little bit of .text; bloat-o-meter for an arm build says Function old new delta strcspn 92 76 -16 strspn 108 76 -32 While here, also remove a stray empty line before EXPORT_SYMBOL(). Link: https://lkml.kernel.org/r/20220328224119.3003834-2-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Andy Shevchenko <andy@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c25
1 files changed, 6 insertions, 19 deletions
diff --git a/lib/string.c b/lib/string.c
index 485777c9da83..6f334420f687 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -517,21 +517,13 @@ EXPORT_SYMBOL(strnlen);
size_t strspn(const char *s, const char *accept)
{
const char *p;
- const char *a;
- size_t count = 0;
for (p = s; *p != '\0'; ++p) {
- for (a = accept; *a != '\0'; ++a) {
- if (*p == *a)
- break;
- }
- if (*a == '\0')
- return count;
- ++count;
+ if (!strchr(accept, *p))
+ break;
}
- return count;
+ return p - s;
}
-
EXPORT_SYMBOL(strspn);
#endif
@@ -544,17 +536,12 @@ EXPORT_SYMBOL(strspn);
size_t strcspn(const char *s, const char *reject)
{
const char *p;
- const char *r;
- size_t count = 0;
for (p = s; *p != '\0'; ++p) {
- for (r = reject; *r != '\0'; ++r) {
- if (*p == *r)
- return count;
- }
- ++count;
+ if (strchr(reject, *p))
+ break;
}
- return count;
+ return p - s;
}
EXPORT_SYMBOL(strcspn);
#endif