From: tip-bot for Arnaldo Carvalho de Melo <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, jolsa@kernel.org, acme@redhat.com,
mingo@kernel.org, treeze.taeung@gmail.com,
linux-kernel@vger.kernel.org, namhyung@kernel.org, hpa@zytor.com
Subject: [tip:perf/core] perf string: Simplify ltrim() implementation
Date: Tue, 11 Apr 2017 22:37:27 -0700 [thread overview]
Message-ID: <tip-w3nk0x3pai2vojk2ab6kdvaw@git.kernel.org> (raw)
Commit-ID: ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1
Gitweb: http://git.kernel.org/tip/ecbe5e10d4ad12dd3da5d9fccd153c529c8c8ce1
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Fri, 7 Apr 2017 12:19:38 -0300
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
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]$
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>
---
tools/perf/util/string.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index bddca51..e8feb14 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;
}
reply other threads:[~2017-04-12 5:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-w3nk0x3pai2vojk2ab6kdvaw@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=hpa@zytor.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=tglx@linutronix.de \
--cc=treeze.taeung@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®