on master help sign in
Use ByteStrings to make writing html and js a bit faster
commitde232b677e587b0692f1626f3db41e402562bb18 authorEvan Czaplicki <info@elm-lang.org> dateWed 25 Sep 2013, 14:25 (13 years ago) parent045852a
2 files changed+13−12
compiler/Compiler.hs+9−8 compiler/Generate/Html.hs+4−4
compiler/Compiler.hs+9−8
@@ -179,7 +179,7 @@ build flags rootFile = do
179179 files <- if make flags then getSortedDependencies noPrelude rootFile else return [rootFile]
180180 let ifaces = if noPrelude then Map.empty else Prelude.interfaces
181181 (moduleName, interfaces) <- buildFiles flags (length files) ifaces "" files
182− js <- foldM appendToOutput "" files
182+ js <- foldM appendToOutput BS.empty files
183183
184184 (extension, code) <- case only_js flags of
185185 True -> do
@@ -187,22 +187,23 @@ build flags rootFile = do
187187 return ("js", genJs js)
188188 False -> do
189189 putStr "Generating HTML ... "
190− runtime <- getRuntime flags
191− return ("html", genHtml $ createHtml runtime (takeBaseName rootFile) (sources js) moduleName "")
190+ rtsPath <- getRuntime flags
191+ return ("html", BS.pack . genHtml $
192+ createHtml rtsPath (takeBaseName rootFile) (sources js) moduleName "")
192193
193194 let targetFile = buildPath flags rootFile extension
194195 createDirectoryIfMissing True (takeDirectory targetFile)
195− writeFile targetFile code
196+ BS.writeFile targetFile code
196197 putStrLn "Done"
197198
198199 where
199− appendToOutput :: String -> FilePath -> IO String
200+ appendToOutput :: BS.ByteString -> FilePath -> IO BS.ByteString
200201 appendToOutput js filePath =
201− do src <- readFile (elmo flags filePath)
202− return (src ++ js)
202+ do src <- BS.readFile (elmo flags filePath)
203+ return (BS.append src js)
203204
204205 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
206207 sources js = map Link (scripts flags) ++
207208 [ Source (if minify flags then Minified else Readable) js ]
208209
compiler/Generate/Html.hs+4−4
@@ -19,7 +19,7 @@ import Generate.JavaScript
1919import Generate.Noscript
2020
2121data JSStyle = Minified | Readable
22−data JSSource = Link String | Source JSStyle String
22+data JSSource = Link String | Source JSStyle BS.ByteString
2323
2424makeScript :: JSSource -> H.Html
2525makeScript source =
@@ -27,9 +27,9 @@ makeScript source =
2727 Link src -> H.script ! A.type_ "text/javascript" ! A.src (H.toValue src) $ ""
2828 Source style src ->
2929 H.script ! A.type_ "text/javascript" $
30− preEscapedToMarkup $ case style of
31− Minified -> BS.unpack . minify . BS.pack $ src
32− Readable -> src
30+ preEscapedToMarkup $ BS.unpack $ case style of
31+ Minified -> minify src
32+ Readable -> src
3333
3434-- |This function compiles Elm code into simple HTML.
3535--