]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib: simplify cpuset if clauses that return
authorSami Kerola <kerolasa@iki.fi>
Mon, 29 May 2017 17:39:22 +0000 (18:39 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Jun 2017 10:22:54 +0000 (12:22 +0200)
There is no need for 'else' when 'if' will return.  In same go move call of
tolower() to last possible moment in char_to_val(), a lot of time hex values
should hit 0-9 range, and it can be omitted.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lib/cpuset.c

index 6d82522f57c23e328f3228e4d749beb706ca6669..011b6882b82b785a8382ed2146d2cc8a5559b465 100644 (file)
@@ -29,23 +29,21 @@ static inline int val_to_char(int v)
 {
        if (v >= 0 && v < 10)
                return '0' + v;
-       else if (v >= 10 && v < 16)
+       if (v >= 10 && v < 16)
                return ('a' - 10) + v;
-       else
-               return -1;
+       return -1;
 }
 
 static inline int char_to_val(int c)
 {
        int cl;
 
-       cl = tolower(c);
        if (c >= '0' && c <= '9')
                return c - '0';
-       else if (cl >= 'a' && cl <= 'f')
+       cl = tolower(c);
+       if (cl >= 'a' && cl <= 'f')
                return cl + (10 - 'a');
-       else
-               return -1;
+       return -1;
 }
 
 static const char *nexttoken(const char *q,  int sep)