From 57a8eca84a1eda99c8cfb63889fa300ba982cb77 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 1 Aug 2011 01:18:33 +0200 Subject: util: optimize strstrip() a bit --- src/util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/util.c b/src/util.c index cbfac6ec3b..1a61a26046 100644 --- a/src/util.c +++ b/src/util.c @@ -1411,21 +1411,18 @@ int reset_all_signal_handlers(void) { } char *strstrip(char *s) { - char *e, *l = NULL; + char *e; /* Drops trailing whitespace. Modifies the string in * place. Returns pointer to first non-space character */ s += strspn(s, WHITESPACE); - for (e = s; *e; e++) - if (!strchr(WHITESPACE, *e)) - l = e; + for (e = strchr(s, 0); e > s; e --) + if (!strchr(WHITESPACE, e[-1])) + break; - if (l) - *(l+1) = 0; - else - *s = 0; + *e = 0; return s; } -- cgit v1.2.3-54-g00ecf