From 2b97d32db53ffb773e10d585e0a184ab40666036 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Thu, 29 Sep 2022 22:50:31 +1000 Subject: [PATCH] renderBox: avoid unnecessary use of dlist `renderBox` uses dlist to grow the result list while doing a render traversal. An ordinary fmap'd list construction suffices and offers a very small but measurable performance boost. Furthermore this is the only place the *dlist* library was used so *brick* no longer depends on it. --- brick.cabal | 1 - src/Brick/Widgets/Core.hs | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/brick.cabal b/brick.cabal index d7f341a..d89293f 100644 --- a/brick.cabal +++ b/brick.cabal @@ -123,7 +123,6 @@ library bimap >= 0.5 && < 0.6, data-clist >= 0.1, directory >= 1.2.5.0, - dlist, exceptions >= 0.10.0, filepath, containers >= 0.5.7, diff --git a/src/Brick/Widgets/Core.hs b/src/Brick/Widgets/Core.hs index 68a1c74..2c16ace 100644 --- a/src/Brick/Widgets/Core.hs +++ b/src/Brick/Widgets/Core.hs @@ -126,7 +126,6 @@ import Control.Monad.State.Strict import Control.Monad.Reader import qualified Data.Foldable as F import qualified Data.Text as T -import qualified Data.DList as DL import qualified Data.Map as M import qualified Data.Set as S import qualified Data.IMap as I @@ -642,15 +641,15 @@ renderBox br ws = let availPrimary = c^.(contextPrimary br) availSecondary = c^.(contextSecondary br) - renderHis _ prev [] = return $ DL.toList prev - renderHis remainingPrimary prev ((i, prim):rest) = do + renderHis _ [] = pure [] + renderHis remainingPrimary ((i, prim):rest) = do result <- render $ limitPrimary br remainingPrimary $ limitSecondary br availSecondary $ cropToContext prim - renderHis (remainingPrimary - (result^.imageL.(to $ imagePrimary br))) - (DL.snoc prev (i, result)) rest + let newRem = remainingPrimary - (result^.imageL.(to $ imagePrimary br)) + ((i, result) :) <$> renderHis newRem rest - renderedHis <- renderHis availPrimary DL.empty his + renderedHis <- renderHis availPrimary his renderedLows <- case lows of [] -> return []