From 39cdcbcdcdab66749e31cd738d689e1d9cd9202c Mon Sep 17 00:00:00 2001 From: V0idk <1439808922@qq.com> Date: Wed, 3 Oct 2018 01:51:33 +0800 Subject: [PATCH 1/2] Optimize strspn. Variable count is redundant. --- lib/string.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/string.c b/lib/string.c index 2c0900a5d51a2a..93a70ba695a5af 100644 --- a/lib/string.c +++ b/lib/string.c @@ -513,7 +513,6 @@ 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) { @@ -521,10 +520,9 @@ size_t strspn(const char *s, const char *accept) break; } if (*a == '\0') - return count; - ++count; + p - s; } - return count; + return p - s; } EXPORT_SYMBOL(strspn); From e2a3d75cd645ebeaa272e01a8bc4212abff30238 Mon Sep 17 00:00:00 2001 From: V0idk <1439808922@qq.com> Date: Fri, 5 Oct 2018 00:36:42 +0800 Subject: [PATCH 2/2] Update string.c --- lib/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/string.c b/lib/string.c index 93a70ba695a5af..e87d713776b477 100644 --- a/lib/string.c +++ b/lib/string.c @@ -520,7 +520,7 @@ size_t strspn(const char *s, const char *accept) break; } if (*a == '\0') - p - s; + return p - s; } return p - s; }