[systemd-devel] [PATCH] util: Rewrite in_charset to use strspn

Lennart Poettering lennart at poettering.net
Tue Mar 11 16:49:08 PDT 2014


On Tue, 11.03.14 16:45, Josh Triplett (josh at joshtriplett.org) wrote:

Can you turn this into an inline function please? If it's that simple it
sounds better to just make it an inline function in the .h file, instead
of the .c file...

> 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) {


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list