Skip to contentSkip to conversation

perf string: Simplify ltrim() implementation

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Apr 12, 2017 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1
Gitweb:     http://git.kernel.org/tip/ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Fri, 7 Apr 2017 12:19:38 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 11 Apr 2017 15:23:39 -0300

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]$

---
 tools/perf/util/string.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
tools/perf/util/string.c +1 -5
index bddca51..e8feb14 100644
@@ -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;
 }