chiark / gitweb /
util: Rewrite in_charset to use strspn
authorJosh Triplett <josh@joshtriplett.org>
Tue, 11 Mar 2014 23:45:56 +0000 (16:45 -0700)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Mar 2014 16:02:06 +0000 (17:02 +0100)
This simplifies in_charset down to a one-liner, and allows for possible
optimizations of strspn in libc.

src/shared/util.c

index 10f113bd240975d7f9fc810c21623ad54aba2e67..e1a11684565f4bc8780422af492238271a988fa1 100644 (file)
@@ -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) {