on master help sign in
Replace countDigits with a faster, more complex version
31c7eb6Bryan O'Sullivan
Data/Text/Lazy/Builder/Int.hs+12−2
@@ -125,8 +125,18 @@ countDigits v0 = go 1 (fromIntegral v0 :: Word64)
125 | v < 10 = k
125 | v < 10 = k
126 | v < 100 = k + 1
126 | v < 100 = k + 1
127 | v < 1000 = k + 2
127 | v < 1000 = k + 2
128− | v < 10000 = k + 3
128+ | v < 1000000000000 =
129+ k + if v < 100000000
130+ then if v < 1000000
131+ then if v < 10000
132+ then 3
133+ else 4 + fin v 100000
134+ else 6 + fin v 10000000
135+ else if v < 10000000000
136+ then 8 + fin v 1000000000
137+ else 10 + fin v 100000000000
129− | otherwise = go (k+4) (v `quot` 10000)
138+ | otherwise = go (k + 12) (v `quot` 1000000000000)
139+ fin v n = if v >= n then 1 else 0
130
140
131hexadecimal :: Integral a => a -> Builder
141hexadecimal :: Integral a => a -> Builder
132{-# SPECIALIZE hexadecimal :: Int -> Builder #-}
142{-# SPECIALIZE hexadecimal :: Int -> Builder #-}