1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

xz: Avoid a compiler warning in progress_speed() in message.c.

This should be smaller too since it avoids the string constants.
This commit is contained in:
Jia Tan 2022-11-07 16:24:14 +02:00 committed by Lasse Collin
parent cf118c0146
commit 1fc6e7dd1f

View file

@ -355,11 +355,8 @@ progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
if (elapsed < 3000) if (elapsed < 3000)
return ""; return "";
static const char unit[][8] = { // The first character of KiB/s, MiB/s, or GiB/s:
"KiB/s", static const char unit[] = { 'K', 'M', 'G' };
"MiB/s",
"GiB/s",
};
size_t unit_index = 0; size_t unit_index = 0;
@ -381,7 +378,7 @@ progress_speed(uint64_t uncompressed_pos, uint64_t elapsed)
// - 999 KiB/s // - 999 KiB/s
// Use big enough buffer to hold e.g. a multibyte decimal point. // Use big enough buffer to hold e.g. a multibyte decimal point.
static char buf[16]; static char buf[16];
snprintf(buf, sizeof(buf), "%.*f %s", snprintf(buf, sizeof(buf), "%.*f %ciB/s",
speed > 9.9 ? 0 : 1, speed, unit[unit_index]); speed > 9.9 ? 0 : 1, speed, unit[unit_index]);
return buf; return buf;
} }