blob: c729265009ca74bd732c8ca5b41823ca32e96cd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
{-# LANGUAGE BangPatterns, CPP, MagicHash, RankNTypes, ScopedTypeVariables, UnboxedTuples #-}
{-# OPTIONS_GHC -O2 -dcmm-lint #-}
module Data.Text.Lazy.Builder.Int ( hexadecimal) where
import GHC.Exts
import Data.Int (Int8)
import Prelude
type Builder = [Char]
singleton :: a -> [a]
singleton x = [x]
hexadecimal :: Int8 -> Builder
hexadecimal i = go i
where
go n | n < 16 = hexDigit n
| otherwise = go (n `quot` 16) <> hexDigit (n `rem` 16)
{-# NOINLINE[0] hexadecimal #-}
hexDigit :: Integral a => a -> Builder
hexDigit n
| n <= 9 = singleton $! i2d (fromIntegral n)
| otherwise = singleton $! toEnum (fromIntegral n + 87)
{-# INLINE hexDigit #-}
{-# INLINE i2d #-}
i2d :: Int -> Char
i2d (I# i#) = C# (chr# (ord# '0'# +# i#))
|