From: Arran Cudbard-Bell Date: Thu, 16 Jun 2022 14:36:54 +0000 (-0500) Subject: Slightly more efficient way of determining trailing zeros for size printing X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fc23b88fdec730db6e7516377723f6113eb73e4;p=thirdparty%2Ffreeradius-server.git Slightly more efficient way of determining trailing zeros for size printing --- diff --git a/src/lib/util/size.c b/src/lib/util/size.c index 18877ebe7cf..f133addb2af 100644 --- a/src/lib/util/size.c +++ b/src/lib/util/size.c @@ -176,21 +176,22 @@ fr_slen_t fr_size_to_str(fr_sbuff_t *out, size_t in) }; fr_size_unit_t const *unit = &base10_units[0]; - int8_t pos2 = fr_low_bit_pos(in) - 1; - int8_t pos10; + uint8_t pos2 = fr_low_bit_pos(in); + uint8_t pos10; size_t tmp; /* * Fast path - Won't be divisible by a power of 1000 or a power of 1024 */ if (pos2 < 3) goto done; + pos--; /* * Get a count of trailing decimal zeroes. */ - for (tmp = in, pos10 = 0; tmp && ((tmp % 10) == 0); pos10++) tmp /= 10; + for (tmp = in, pos10 = 0; tmp && ((tmp % 1000) == 0); pos10++) tmp /= 1000; - if (pos10 >= 3) unit = &base10_units[(pos10) / 3]; + if (pos10 > 0) unit = &base10_units[pos10]; else if (pos2 >= 10) unit = &base2_units[pos2 / 10]; done: