git.iko.soy/typeable/cabal2nix
on master help sign in
Identifier: disable case-awareness in Ord instance

Case-insensitive comparisons cause a massive performance hit. I'll need to find a better way to get the pretty-printed output sorted the way I'd like it to be.

commit7ad6d7d17b3598d4c7dfe3a2c8b8a80f81b691df authorPeter Simons <simons@cryp.to> dateThu 20 Aug 2015, 22:24 (11 years ago) parent37a7878
1 file changed+3−24
src/Language/Nix/Identifier.hs+3−24
src/Language/Nix/Identifier.hs+3−24
@@ -4,13 +4,11 @@
44module Language.Nix.Identifier ( Identifier, ident, quote, needsQuoting ) where
55
66import Control.DeepSeq.Generics
7−import Internal.Lens
8−import Data.Char
9−import Data.Function ( on )
107import Data.String
118import Distribution.Nixpkgs.Util.PrettyPrinting ( Pretty(..), text )
12−import Text.Regex.Posix
139import GHC.Generics ( Generic )
10+import Internal.Lens
11+import Text.Regex.Posix
1412
1513-- | Identifiers in Nix are essentially strings. Reasonable people restrict
1614-- themselves to identifiers of the form @[a-zA-Z\_][a-zA-Z0-9\_\'\-]*@,
@@ -22,22 +20,6 @@ import GHC.Generics ( Generic )
2220-- (Identifier "test",test)
2321-- >>> let i = Identifier "foo.bar" in (i, pPrint i)
2422-- (Identifier "foo.bar","foo.bar")
25−--
26−-- The 'Ord' instance for identifiers is aware of character case:
27−--
28−-- >>> Identifier "abc" == Identifier "ABC"
29−-- False
30−-- >>> Identifier "abc" < Identifier "ABC"
31−-- False
32−-- >>> Identifier "abc" > Identifier "ABC"
33−-- True
34−-- >>> Identifier "X" > Identifier "a"
35−-- True
36−-- >>> Identifier "x" > Identifier "A"
37−-- True
38−--
39−-- prop> \str -> Identifier str == Identifier str
40−-- prop> \str -> any (`elem` ['a'..'z']) str ==> Identifier (map toLower str) /= Identifier (map toUpper str)
4123
4224newtype Identifier = Identifier String
4325 deriving (Show, Eq, IsString, Generic)
@@ -48,10 +30,7 @@ instance Pretty Identifier where
4830 pPrint i = text (i ^. ident . to quote)
4931
5032instance Ord Identifier where
51− compare (Identifier a) (Identifier b) =
52− case (compare `on` map toLower) a b of
53− EQ -> compare a b
54− r -> r
33+ compare (Identifier a) (Identifier b) = compare a b
5534
5635instance NFData Identifier where rnf = genericRnf
5736