[PATCH v3 2/2] stop_progress_msg(): simplification function
- From
Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com>
- Date
- Feb 16, 2017, 23:32 UTC
- Message-ID
- <20170216233249.24757-3-franchesko.salias.hudro.pedros@gmail.com>
- In-Reply-To
- <20170216233249.24757-1-franchesko.salias.hudro.pedros@gmail.com>
stop_progress_msg() is rarely used and is not demanding to performance. Use dynamically allocates memory.
Signed-off-by: Maxim Moseychuk <franchesko.salias.hudro.pedros@gmail.com> --- progress.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/progress.c b/progress.c index 76a88c573..29378caa0 100644 --- a/progress.c +++ b/progress.c @@ -243,21 +243,18 @@ void stop_progress_msg(struct progress **p_progress, const char *msg) *p_progress = NULL; if (progress->last_value != -1) { /* Force the last update */ - char buf[128], *bufp; - size_t len = strlen(msg) + 5; + char *buf; struct throughput *tp = progress->throughput; - bufp = (len < sizeof(buf)) ? buf : xmallocz(len); if (tp) { unsigned int rate = !tp->avg_misecs ? 0 : tp->avg_bytes / tp->avg_misecs; throughput_string(&tp->display, tp->curr_total, rate); } progress_update = 1; - xsnprintf(bufp, len + 1, ", %s.\n", msg); - display(progress, progress->last_value, bufp); - if (buf != bufp) - free(bufp); + buf = xstrfmt(", %s.\n", msg); + display(progress, progress->last_value, buf); + free(buf); } clear_progress_signal(); if (progress->throughput)
-- 2.11.1