diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2021-02-26 13:11:23 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-02-28 06:10:42 -0500 |
commit | 915daf51357175fcc31a37c0aaf2347875560269 (patch) | |
tree | 801e86abb7e0d07285e02753c7738a39913c6899 | |
parent | 2454bb10a81e997100dd45b173ea11f2b24cf390 (diff) | |
download | haskell-915daf51357175fcc31a37c0aaf2347875560269.tar.gz |
Reduce code bloat in `Ord Literal` instance (#19443)
Reduce code bloat by replacing a call to `(==)` (which is defined in
terms of `compare`) and to `compare` by a single call to `compare`,
utilising the `Semigroup Ordering` instance.
The compiler was eliminate the code bloat before, so this is a rather
cosmetical improvement.
Fixes #19443.
-rw-r--r-- | compiler/GHC/Types/Literal.hs | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/compiler/GHC/Types/Literal.hs b/compiler/GHC/Types/Literal.hs index 90c253c12a..be23f2405e 100644 --- a/compiler/GHC/Types/Literal.hs +++ b/compiler/GHC/Types/Literal.hs @@ -6,6 +6,7 @@ {-# LANGUAGE CPP, DeriveDataTypeable, ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} +{-# LANGUAGE MagicHash #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} @@ -87,6 +88,7 @@ import Data.Int import Data.Word import Data.Char import Data.Data ( Data ) +import GHC.Exts import Numeric ( fromRat ) {- @@ -871,22 +873,11 @@ cmpLit (LitFloat a) (LitFloat b) = a `compare` b cmpLit (LitDouble a) (LitDouble b) = a `compare` b cmpLit (LitLabel a _ _) (LitLabel b _ _) = a `lexicalCompareFS` b cmpLit (LitNumber nt1 a) (LitNumber nt2 b) - | nt1 == nt2 = a `compare` b - | otherwise = nt1 `compare` nt2 + = (nt1 `compare` nt2) `mappend` (a `compare` b) cmpLit (LitRubbish b1) (LitRubbish b2) = b1 `compare` b2 cmpLit lit1 lit2 - | litTag lit1 < litTag lit2 = LT - | otherwise = GT - -litTag :: Literal -> Int -litTag (LitChar _) = 1 -litTag (LitString _) = 2 -litTag (LitNullAddr) = 3 -litTag (LitFloat _) = 4 -litTag (LitDouble _) = 5 -litTag (LitLabel _ _ _) = 6 -litTag (LitNumber {}) = 7 -litTag (LitRubbish {}) = 8 + | isTrue# (dataToTag# lit1 <# dataToTag# lit2) = LT + | otherwise = GT {- Printing |