瀏覽代碼

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>
Arnaldo Carvalho de Melo 8 年之前
父節點
當前提交
ecbe5e10d4
共有 1 個文件被更改,包括 1 次插入5 次删除
  1. 1 5
      tools/perf/util/string.c

+ 1 - 5
tools/perf/util/string.c

@@ -322,12 +322,8 @@ char *strxfrchar(char *s, char from, char to)
  */
  */
 char *ltrim(char *s)
 char *ltrim(char *s)
 {
 {
-	int len = strlen(s);
-
-	while (len && isspace(*s)) {
-		len--;
+	while (isspace(*s))
 		s++;
 		s++;
-	}
 
 
 	return s;
 	return s;
 }
 }