From: Arnaldo Carvalho de Melo Date: Fri, 7 Apr 2017 15:19:38 +0000 (-0300) Subject: perf string: Simplify ltrim() implementation X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git perf string: Simplify ltrim() implementation We don't need to use strlen(), a var, or check for the end explicitely, isspace('\0') is false: [acme@jouet c]$ cat ltrim.c #include #include static char *ltrim(char *s) { while (isspace(*s)) ++s; return s; } int main(void) { printf("ltrim(\"\")='%s'\n", ltrim("")); return 0; } [acme@jouet c]$ ./ltrim ltrim("")='' [acme@jouet c]$ Cc: Jiri Olsa Cc: Namhyung Kim Cc: Taeung Song Link: http://lkml.kernel.org/n/tip-w3nk0x3pai2vojk2ab6kdvaw@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c index bddca519dd58..e8feb142c9c9 100644 --- a/tools/perf/util/string.c +++ b/tools/perf/util/string.c @@ -322,12 +322,8 @@ char *strxfrchar(char *s, char from, char to) */ char *ltrim(char *s) { - int len = strlen(s); - - while (len && isspace(*s)) { - len--; + while (isspace(*s)) s++; - } return s; }