From cd0e55276e8dbe9677115966cbc55d925442eaed Mon Sep 17 00:00:00 2001 From: Mitsutoshi Aoe Date: Sat, 31 Dec 2016 08:44:34 +0900 Subject: [PATCH] Use DList to avoid repetitive Data.List.++ --- brick.cabal | 1 + src/Brick/Widgets/Core.hs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/brick.cabal b/brick.cabal index 84e87c6..15d1b9a 100644 --- a/brick.cabal +++ b/brick.cabal @@ -81,6 +81,7 @@ library vty >= 5.12, transformers, data-default, + dlist, containers, microlens >= 0.3.0.0, microlens-th, diff --git a/src/Brick/Widgets/Core.hs b/src/Brick/Widgets/Core.hs index 94aea96..a1d516d 100644 --- a/src/Brick/Widgets/Core.hs +++ b/src/Brick/Widgets/Core.hs @@ -93,6 +93,7 @@ import Control.Monad.Trans.Class (lift) import qualified Data.Foldable as F import qualified Data.Text as T import Data.Default +import qualified Data.DList as DL import qualified Data.Map as M import qualified Data.Set as S import qualified Data.Function as DF @@ -438,14 +439,14 @@ renderBox br ws = let availPrimary = c^.(contextPrimary br) availSecondary = c^.(contextSecondary br) - renderHis _ prev [] = return prev + renderHis _ prev [] = return $ DL.toList prev renderHis remainingPrimary prev ((i, prim):rest) = do result <- render $ limitPrimary br remainingPrimary $ limitSecondary br availSecondary $ cropToContext prim - renderHis (remainingPrimary - (result^.imageL.(to $ imagePrimary br))) (prev ++ [(i, result)]) rest + renderHis (remainingPrimary - (result^.imageL.(to $ imagePrimary br))) (DL.snoc prev (i, result)) rest - renderedHis <- renderHis availPrimary [] his + renderedHis <- renderHis availPrimary DL.empty his renderedLows <- case lows of [] -> return []