From: Yedidya Feldblum Date: Tue, 26 Dec 2017 02:32:30 +0000 (-0800) Subject: Format digits10 X-Git-Tag: v2018.01.01.00~20 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=3764ca2b6e84a6a3614943b7df00646677dc1bea Format digits10 Summary: [Folly] Format `digits10`. Reviewed By: Orvid Differential Revision: D6636190 fbshipit-source-id: 6e6b834f6c9070d58f8e2b085b09df8b857fe878 --- diff --git a/folly/Conv.h b/folly/Conv.h index 3c29a02d..25c513f7 100644 --- a/folly/Conv.h +++ b/folly/Conv.h @@ -326,7 +326,7 @@ inline uint32_t digits10(uint64_t v) { }; // "count leading zeroes" operation not valid; for 0; special case this. - if UNLIKELY (! v) { + if (UNLIKELY(!v)) { return 1; } @@ -341,16 +341,24 @@ inline uint32_t digits10(uint64_t v) { // return that log_10 lower bound, plus adjust if input >= 10^(that bound) // in case there's a small error and we misjudged length. - return minLength + (uint32_t) (UNLIKELY (v >= powersOf10[minLength])); + return minLength + uint32_t(v >= powersOf10[minLength]); #else uint32_t result = 1; - for (;;) { - if (LIKELY(v < 10)) return result; - if (LIKELY(v < 100)) return result + 1; - if (LIKELY(v < 1000)) return result + 2; - if (LIKELY(v < 10000)) return result + 3; + while (true) { + if (LIKELY(v < 10)) { + return result; + } + if (LIKELY(v < 100)) { + return result + 1; + } + if (LIKELY(v < 1000)) { + return result + 2; + } + if (LIKELY(v < 10000)) { + return result + 3; + } // Skip ahead by 4 orders of magnitude v /= 10000U; result += 4;