summaryrefslogtreecommitdiff
path: root/libraries/base
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-05-27 15:53:25 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-28 15:32:44 -0400
commitdf997fac54bbadd399593f49228b6292e71145f1 (patch)
tree8977d9b8b897b1760436ce75df7a0cbea2d6bbc3 /libraries/base
parentf74204c4f6f3f386c9688ca45a893f68894ecacd (diff)
downloadhaskell-df997fac54bbadd399593f49228b6292e71145f1.tar.gz
Use quotRemWord in showWord
Using the following high-quality benchmark (with -O2): main :: IO () main = do let go 0 = "" go n@(W# n#) = showWord n# (go (n -1)) print $ length (go 10000000) I get the following performance results: - remWord+quotRem: 0,76s user 0,00s system 99% cpu 0,762 total - quotRemWord: 0,45s user 0,01s system 99% cpu 0,456 total Note that showSignedInt already uses quotRemInt.
Diffstat (limited to 'libraries/base')
-rw-r--r--libraries/base/GHC/Show.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/libraries/base/GHC/Show.hs b/libraries/base/GHC/Show.hs
index 0d90006432..04fbcb6112 100644
--- a/libraries/base/GHC/Show.hs
+++ b/libraries/base/GHC/Show.hs
@@ -202,9 +202,11 @@ instance Show Word where
showWord :: Word# -> ShowS
showWord w# cs
| isTrue# (w# `ltWord#` 10##) = C# (chr# (ord# '0'# +# word2Int# w#)) : cs
- | otherwise = case chr# (ord# '0'# +# word2Int# (w# `remWord#` 10##)) of
- c# ->
- showWord (w# `quotWord#` 10##) (C# c# : cs)
+ | otherwise =
+ let
+ !(# q, r #) = quotRemWord# w# 10##
+ !c# = chr# (ord# '0'# +# word2Int# r)
+ in showWord q (C# c# : cs)
-- | @since 2.01
deriving instance Show a => Show (Maybe a)