Merge pull request #15 from eigengrau/space-leak

Address space leaks in renderFinal and str
This commit is contained in:
Jonathan Daugherty 2015-08-24 08:34:07 -07:00
commit e4ccca052c
3 changed files with 9 additions and 4 deletions

View File

@ -87,7 +87,8 @@ library
contravariant,
text,
text-zipper >= 0.2.1,
template-haskell
template-haskell,
deepseq >= 1.4 && < 1.5
executable brick-visibility-demo
if !flag(demos)

View File

@ -78,6 +78,7 @@ import qualified Data.Function as DF
import Data.List (sortBy, partition)
import Control.Lens (Lens')
import qualified Graphics.Vty as V
import Control.DeepSeq
import Brick.Types
import Brick.Types.Internal
@ -125,10 +126,11 @@ str :: String -> Widget
str s =
Widget Fixed Fixed $ do
c <- getContext
let theLines = lines s
let theLines = fixEmpty <$> (dropUnused . lines) s
fixEmpty [] = " "
fixEmpty l = l
case fixEmpty <$> theLines of
dropUnused l = take (availWidth c) <$> take (availHeight c) l
case force theLines of
[] -> return def
[one] -> return $ def & imageL .~ (V.string (c^.attrL) one)
multiple ->

View File

@ -1,3 +1,5 @@
{-# LANGUAGE BangPatterns #-}
module Brick.Widgets.Internal
( renderFinal
, cropToContext
@ -24,7 +26,7 @@ renderFinal :: AttrMap
-> (RenderState, V.Picture, Maybe CursorLocation)
renderFinal aMap layerRenders sz chooseCursor rs = (newRS, pic, theCursor)
where
(layerResults, newRS) = flip runState rs $ sequence $
(layerResults, !newRS) = flip runState rs $ sequence $
(\p -> runReaderT p ctx) <$>
(render <$> cropToContext <$> layerRenders)
ctx = Context def (fst sz) (snd sz) def aMap