-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize compiler code to reduce compile times
Refactor the implementation of the Elm compiler in various places to reduce memory allocations and transformation steps during compilation.
- Loading branch information
Showing
6 changed files
with
291 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
implement/elm-time/ElmTime/compile-elm-program/src/Hex.elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
module Hex exposing (..) | ||
|
||
{-| Convert a decimal integer to a hexdecimal string such as `"abc94f"`. | ||
Hex.toString 165 == "a5" | ||
-} | ||
|
||
|
||
toString : Int -> String | ||
toString num = | ||
String.fromList | ||
(if num < 0 then | ||
'-' :: unsafePositiveToDigits [] (negate num) | ||
|
||
else | ||
unsafePositiveToDigits [] num | ||
) | ||
|
||
|
||
{-| ONLY EVER CALL THIS WITH POSITIVE INTEGERS! | ||
-} | ||
unsafePositiveToDigits : List Char -> Int -> List Char | ||
unsafePositiveToDigits digits num = | ||
if num < 16 then | ||
unsafeToDigit num :: digits | ||
|
||
else | ||
unsafePositiveToDigits (unsafeToDigit (modBy 16 num) :: digits) (num // 16) | ||
|
||
|
||
{-| ONLY EVER CALL THIS WITH INTEGERS BETWEEN 0 and 15! | ||
-} | ||
unsafeToDigit : Int -> Char | ||
unsafeToDigit num = | ||
case num of | ||
0 -> | ||
'0' | ||
|
||
1 -> | ||
'1' | ||
|
||
2 -> | ||
'2' | ||
|
||
3 -> | ||
'3' | ||
|
||
4 -> | ||
'4' | ||
|
||
5 -> | ||
'5' | ||
|
||
6 -> | ||
'6' | ||
|
||
7 -> | ||
'7' | ||
|
||
8 -> | ||
'8' | ||
|
||
9 -> | ||
'9' | ||
|
||
10 -> | ||
'a' | ||
|
||
11 -> | ||
'b' | ||
|
||
12 -> | ||
'c' | ||
|
||
13 -> | ||
'd' | ||
|
||
14 -> | ||
'e' | ||
|
||
15 -> | ||
'f' | ||
|
||
_ -> | ||
-- if this ever gets called with a number over 15, it will never | ||
-- terminate! If that happens, debug further by uncommenting this: | ||
-- | ||
-- Debug.todo ("Tried to convert " ++ toString num ++ " to hexadecimal.") | ||
unsafeToDigit num |
Oops, something went wrong.