From ac79db6a3b8c9d1815dc4f506d55bc6a2a4e34dd Mon Sep 17 00:00:00 2001 From: Martin Lewis Date: Thu, 11 Jun 2020 15:45:57 -0500 Subject: procps: code shrink function old new delta skip_whitespace_if_prefixed_with - 17 +17 procps_read_smaps 911 854 -57 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 17/-57) Total: -40 bytes Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- libbb/procps.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libbb/procps.c b/libbb/procps.c index af3ad86..4cc3cb2 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -177,6 +177,15 @@ static char *skip_fields(char *str, int count) } #endif +static char* skip_whitespace_if_prefixed_with(char *buf, const char *prefix) +{ + char *tp = is_prefixed_with(buf, prefix); + if (tp) { + tp = skip_whitespace(tp); + } + return tp; +} + #if ENABLE_FEATURE_TOPMEM || ENABLE_PMAP int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, void (*cb)(struct smaprec *, void *), void *data) @@ -207,8 +216,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, char *tp, *p; #define SCAN(S, X) \ - if ((tp = is_prefixed_with(buf, S)) != NULL) { \ - tp = skip_whitespace(tp); \ + if ((tp = skip_whitespace_if_prefixed_with(buf, S)) != NULL) { \ total->X += currec.X = fast_strtoul_10(&tp); \ continue; \ } -- cgit v1.1