| 286 | } |
| 287 | |
| 288 | inline static unsigned CountDecimalDigit32(uint32_t n) { |
| 289 | #if defined(_MSC_VER) || defined(__GNUC__) |
| 290 | static const uint32_t powers_of_10[] = { |
| 291 | 0, |
| 292 | 10, |
| 293 | 100, |
| 294 | 1000, |
| 295 | 10000, |
| 296 | 100000, |
| 297 | 1000000, |
| 298 | 10000000, |
| 299 | 100000000, |
| 300 | 1000000000 |
| 301 | }; |
| 302 | #ifdef _MSC_VER |
| 303 | unsigned long i = 0; |
| 304 | _BitScanReverse(&i, n | 1); |
| 305 | uint32_t t = (i + 1) * 1233 >> 12; |
| 306 | #elif __GNUC__ |
| 307 | uint32_t t = (32 - __builtin_clz(n | 1)) * 1233 >> 12; |
| 308 | #endif |
| 309 | return t - (n < powers_of_10[t]) + 1; |
| 310 | #else |
| 311 | if (n < 10) return 1; |
| 312 | if (n < 100) return 2; |
| 313 | if (n < 1000) return 3; |
| 314 | if (n < 10000) return 4; |
| 315 | if (n < 100000) return 5; |
| 316 | if (n < 1000000) return 6; |
| 317 | if (n < 10000000) return 7; |
| 318 | if (n < 100000000) return 8; |
| 319 | if (n < 1000000000) return 9; |
| 320 | return 10; |
| 321 | #endif |
| 322 | } |
| 323 | |
| 324 | inline static void Uint32ToStr(uint32_t value, char* buffer) { |
| 325 | const char kDigitsLut[200] = { |