aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/perf/util/string.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-04-07 12:19:38 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-04-11 15:23:39 -0300
commitecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1 (patch)
treeb24dd13689e734daf441ea219efeb742bf8c73c4 /tools/perf/util/string.c
parentperf tools: Refactor the code to strip command name with {l,r}trim() (diff)
downloadwireguard-linux-ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1.tar.xz
wireguard-linux-ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1.zip
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 <ctype.h> #include <stdio.h> 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 <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Taeung Song <treeze.taeung@gmail.com> Link: http://lkml.kernel.org/n/tip-w3nk0x3pai2vojk2ab6kdvaw@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/string.c')
-rw-r--r--tools/perf/util/string.c6
1 files changed, 1 insertions, 5 deletions
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;
}