on master help sign in
Use ByteStrings to make writing html and js a bit faster
de232b6Evan Czaplicki
compiler/Compiler.hs+9−8
@@ -179,7 +179,7 @@ build flags rootFile = do
179 files <- if make flags then getSortedDependencies noPrelude rootFile else return [rootFile]
179 files <- if make flags then getSortedDependencies noPrelude rootFile else return [rootFile]
180 let ifaces = if noPrelude then Map.empty else Prelude.interfaces
180 let ifaces = if noPrelude then Map.empty else Prelude.interfaces
181 (moduleName, interfaces) <- buildFiles flags (length files) ifaces "" files
181 (moduleName, interfaces) <- buildFiles flags (length files) ifaces "" files
182− js <- foldM appendToOutput "" files
182+ js <- foldM appendToOutput BS.empty files
183
183
184 (extension, code) <- case only_js flags of
184 (extension, code) <- case only_js flags of
185 True -> do
185 True -> do
@@ -187,22 +187,23 @@ build flags rootFile = do
187 return ("js", genJs js)
187 return ("js", genJs js)
188 False -> do
188 False -> do
189 putStr "Generating HTML ... "
189 putStr "Generating HTML ... "
190− runtime <- getRuntime flags
190+ rtsPath <- getRuntime flags
191+ return ("html", BS.pack . genHtml $
191− return ("html", genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) moduleName "")
192+ createHtml rtsPath (takeBaseName rootFile) (sources js) moduleName "")
192
193
193 let targetFile = buildPath flags rootFile extension
194 let targetFile = buildPath flags rootFile extension
194 createDirectoryIfMissing True (takeDirectory targetFile)
195 createDirectoryIfMissing True (takeDirectory targetFile)
195− writeFile targetFile code
196+ BS.writeFile targetFile code
196 putStrLn "Done"
197 putStrLn "Done"
197
198
198 where
199 where
199− appendToOutput :: String -> FilePath -> IO String
200+ appendToOutput :: BS.ByteString -> FilePath -> IO BS.ByteString
200 appendToOutput js filePath =
201 appendToOutput js filePath =
201− do src <- readFile (elmo flags filePath)
202+ do src <- BS.readFile (elmo flags filePath)
202− return (src ++ js)
203+ return (BS.append src js)
203
204
204 genHtml = if minify flags then Normal.renderHtml else Pretty.renderHtml
205 genHtml = if minify flags then Normal.renderHtml else Pretty.renderHtml
205− genJs = if minify flags then BS.unpack . JS.minify . BS.pack else id
206+ genJs = if minify flags then JS.minify else id
206 sources js = map Link (scripts flags) ++
207 sources js = map Link (scripts flags) ++
207 [ Source (if minify flags then Minified else Readable) js ]
208 [ Source (if minify flags then Minified else Readable) js ]
208
209
compiler/Generate/Html.hs+4−4
@@ -19,7 +19,7 @@ import Generate.JavaScript
19import Generate.Noscript
19import Generate.Noscript
20
20
21data JSStyle = Minified | Readable
21data JSStyle = Minified | Readable
22−data JSSource = Link String | Source JSStyle String
22+data JSSource = Link String | Source JSStyle BS.ByteString
23
23
24makeScript :: JSSource -> H.Html
24makeScript :: JSSource -> H.Html
25makeScript source =
25makeScript source =
@@ -27,9 +27,9 @@ makeScript source =
27 Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
27 Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
28 Source style src ->
28 Source style src ->
29 H.script ! A.type_ "text/javascript" $
29 H.script ! A.type_ "text/javascript" $
30− preEscapedToMarkup $ case style of
30+ preEscapedToMarkup $ BS.unpack $ case style of
31− Minified -> BS.unpack . minify . BS.pack $ src
31+ Minified -> minify src
32− Readable -> src
32+ Readable -> src
33
33
34-- |This function compiles Elm code into simple HTML.
34-- |This function compiles Elm code into simple HTML.
35--
35--