From 49f5059152b74d220f8673d9c7ae35a3ab484c44 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 5 Apr 2021 21:05:14 +1200 Subject: [PATCH] Bundle readStrict implementation. --- src/Input.hs | 2 +- src/Links.hs | 2 +- src/Render.hs | 1 - src/Types.hs | 10 ++++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Input.hs b/src/Input.hs index 9583001..b6dfbcc 100644 --- a/src/Input.hs +++ b/src/Input.hs @@ -1,7 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE PatternSynonyms, ViewPatterns #-} -module Input(fetchDocument, pageForText, applyCSScharset) where +module Input(fetchDocument, pageForText, applyCSScharset, readStrict) where import Data.Text.Lazy (fromStrict) import qualified Data.Text as Txt diff --git a/src/Links.hs b/src/Links.hs index ecf7283..072de13 100644 --- a/src/Links.hs +++ b/src/Links.hs @@ -166,7 +166,7 @@ updateSuggestions page = do let path = dir "suggestions.gmni" exists <- doesFileExist path suggestions <- if not exists then return [] else do - file <- Prelude.readFile path + file <- readStrict path return [line' | line <- lines file, line'@(_:uri':_) <- [words line], not (pack uri' `Set.member` visitedURLs page)] let suggestions' = suggestions ++ nub [["=>", uri', domain] | link <- links, diff --git a/src/Render.hs b/src/Render.hs index 46af34f..e5f4f94 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -12,7 +12,6 @@ import Data.FileEmbed import Data.Maybe (fromMaybe, maybeToList) import Text.Read (readMaybe) -import Debug.Trace (trace) --- External Rhapsode subcomponents import qualified Data.CSS.Syntax.StyleSheet as CSS diff --git a/src/Types.hs b/src/Types.hs index a4da66e..181716b 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -1,5 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} -module Types(CArray, Page(..), Application(..), buildDirFile) where +module Types(CArray, Page(..), Application(..), buildDirFile, readStrict) where import System.Directory (getCurrentDirectory) -- default referer URI import SpeechStyle (SpeechStyle) @@ -49,11 +49,13 @@ loadVisited = do exists <- doesFileExist path if exists then do - file <- Prelude.readFile path -- Can't leave this file locked when I'll shortly append to it! - let hist = length file `seq` Set.fromList [Txt.pack uri | _:uri:_ <- map words $ lines file] - hist `par` return hist + file <- readStrict path + let hist = Set.fromList [Txt.pack uri | _:uri:_ <- map words $ lines file] + return hist else return Set.empty +readStrict path = do s <- Prelude.readFile path; length s `seq` return s + c_initialReferer = do cwd <- getCurrentDirectory hist <- loadVisited -- 2.30.2