Skip to content

Commit 2cb3b30

Browse files
committed
Generate full paradigm for case conversions, GHC is extremely good at compiling huge cases
1 parent cd45807 commit 2cb3b30

File tree

4 files changed

+5519
-18
lines changed

4 files changed

+5519
-18
lines changed

scripts/CaseFolding.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ parseCF :: FilePath -> IO (Either ParseError CaseFolding)
3535
parseCF name = parse entries name <$> readFile name
3636

3737
mapCF :: CaseFolding -> [String]
38-
mapCF (CF _ ms) = typ ++ (map nice . filter p $ ms) ++ [last]
38+
mapCF (CF _ ms) = typ ++ map printUnusual ms' ++ map printUsual usual ++ [last]
3939
where
40+
ms' = filter p ms
41+
p f = status f `elem` "CF" &&
42+
mapping f /= [toLower (code f)]
43+
unusual = map code ms'
44+
usual = filter (\c -> toLower c /= c && c `notElem` unusual) [minBound..maxBound]
45+
4046
typ = ["foldMapping :: Char# -> _"
4147
,"{-# NOINLINE foldMapping #-}"
4248
,"foldMapping = \\case"]
4349
last = " _ -> unI64 0"
44-
nice c = " -- " ++ name c ++ "\n" ++
50+
printUnusual c = " -- " ++ name c ++ "\n" ++
4551
" " ++ showC (code c) ++ "# -> unI64 " ++ show (ord x + (ord y `shiftL` 21) + (ord z `shiftL` 42))
4652
where x:y:z:_ = mapping c ++ repeat '\0'
47-
p f = status f `elem` "CF" &&
48-
mapping f /= [toLower (code f)]
53+
printUsual c = " " ++ showC c ++ "# -> unI64 " ++ show (ord (toLower c))

scripts/SpecialCasing.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,23 @@ parseSC name = parse entries name <$> readFile name
4141
mapSC :: String -> (Case -> String) -> (Char -> Char) -> SpecialCasing
4242
-> [String]
4343
mapSC which access twiddle (SC _ ms) =
44-
typ ++ (map nice . filter p $ ms) ++ [last]
44+
typ ++ map printUnusual ms' ++ map printUsual usual ++ [last]
4545
where
46+
ms' = filter p ms
47+
p c = [k] /= a && a /= [twiddle k] && null (conditions c)
48+
where a = access c
49+
k = code c
50+
unusual = map code ms'
51+
usual = filter (\c -> twiddle c /= c && c `notElem` unusual) [minBound..maxBound]
52+
4653
typ = [which ++ "Mapping :: Char# -> _"
4754
,"{-# NOINLINE " ++ which ++ "Mapping #-}"
4855
,which ++ "Mapping = \\case"]
4956
last = " _ -> unI64 0"
50-
nice c = " -- " ++ name c ++ "\n" ++
57+
printUnusual c = " -- " ++ name c ++ "\n" ++
5158
" " ++ showC (code c) ++ "# -> unI64 " ++ show (ord x + (ord y `shiftL` 21) + (ord z `shiftL` 42))
5259
where x:y:z:_ = access c ++ repeat '\0'
53-
p c = [k] /= a && a /= [twiddle k] && null (conditions c)
54-
where a = access c
55-
k = code c
60+
printUsual c = " " ++ showC c ++ "# -> unI64 " ++ show (ord (twiddle c))
5661

5762
ucFirst (c:cs) = toUpper c : cs
5863
ucFirst [] = []

0 commit comments

Comments
 (0)