[systemd-commits] 2 commits - src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Wed Mar 12 09:05:31 PDT 2014


 src/shared/util.c |   13 -------------
 src/shared/util.h |    6 +++++-
 2 files changed, 5 insertions(+), 14 deletions(-)

New commits:
commit 01f83c1c765db13e20a241a48733333360457718
Author: Josh Triplett <josh at joshtriplett.org>
Date:   Tue Mar 11 18:51:17 2014 -0700

    util: Make in_charset a static inline in util.h
    
    With in_charset now reduced to a one-liner (plus asserts), make it a
    static inline.

diff --git a/src/shared/util.c b/src/shared/util.c
index e1a1168..9e8cd54 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -920,12 +920,6 @@ char *delete_chars(char *s, const char *bad) {
         return s;
 }
 
-bool in_charset(const char *s, const char* charset) {
-        assert(s);
-        assert(charset);
-        return s[strspn(s, charset)] == '\0';
-}
-
 char *file_in_same_dir(const char *path, const char *filename) {
         char *e, *r;
         size_t k;
diff --git a/src/shared/util.h b/src/shared/util.h
index cc52ae7..81831e2 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -531,7 +531,11 @@ char *strjoin(const char *x, ...) _sentinel_;
 
 bool is_main_thread(void);
 
-bool in_charset(const char *s, const char* charset) _pure_;
+static inline bool _pure_ in_charset(const char *s, const char* charset) {
+        assert(s);
+        assert(charset);
+        return s[strspn(s, charset)] == '\0';
+}
 
 int block_get_whole_disk(dev_t d, dev_t *ret);
 

commit e0333c7314e89c0bc268bd20c5e247a7c907ab34
Author: Josh Triplett <josh at joshtriplett.org>
Date:   Tue Mar 11 16:45:56 2014 -0700

    util: Rewrite in_charset to use strspn
    
    This simplifies in_charset down to a one-liner, and allows for possible
    optimizations of strspn in libc.

diff --git a/src/shared/util.c b/src/shared/util.c
index 10f113b..e1a1168 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) {



More information about the systemd-commits mailing list