[systemd-devel] [PATCH] util: Rewrite in_charset to use strspn
Josh Triplett
josh at joshtriplett.org
Tue Mar 11 16:45:56 PDT 2014
This simplifies in_charset down to a one-liner, and allows for possible
optimizations of strspn in libc.
---
src/shared/util.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/src/shared/util.c b/src/shared/util.c
index d28caae..82326df 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -921,16 +921,9 @@ char *delete_chars(char *s, const char *bad) {
}
bool in_charset(const char *s, const char* charset) {
- const char *i;
-
assert(s);
assert(charset);
-
- for (i = s; *i; i++)
- if (!strchr(charset, *i))
- return false;
-
- return true;
+ return s[strspn(s, charset)] == '\0';
}
char *file_in_same_dir(const char *path, const char *filename) {
--
1.9.0
More information about the systemd-devel
mailing list