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.
This commit is contained in:
Fraser Tweedale 2022-09-29 22:50:31 +10:00
parent 3417a47413
commit 2b97d32db5
2 changed files with 5 additions and 7 deletions

View File

@ -123,7 +123,6 @@ library
bimap >= 0.5 && < 0.6, bimap >= 0.5 && < 0.6,
data-clist >= 0.1, data-clist >= 0.1,
directory >= 1.2.5.0, directory >= 1.2.5.0,
dlist,
exceptions >= 0.10.0, exceptions >= 0.10.0,
filepath, filepath,
containers >= 0.5.7, containers >= 0.5.7,

View File

@ -126,7 +126,6 @@ import Control.Monad.State.Strict
import Control.Monad.Reader import Control.Monad.Reader
import qualified Data.Foldable as F import qualified Data.Foldable as F
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.DList as DL
import qualified Data.Map as M import qualified Data.Map as M
import qualified Data.Set as S import qualified Data.Set as S
import qualified Data.IMap as I import qualified Data.IMap as I
@ -642,15 +641,15 @@ renderBox br ws =
let availPrimary = c^.(contextPrimary br) let availPrimary = c^.(contextPrimary br)
availSecondary = c^.(contextSecondary br) availSecondary = c^.(contextSecondary br)
renderHis _ prev [] = return $ DL.toList prev renderHis _ [] = pure []
renderHis remainingPrimary prev ((i, prim):rest) = do renderHis remainingPrimary ((i, prim):rest) = do
result <- render $ limitPrimary br remainingPrimary result <- render $ limitPrimary br remainingPrimary
$ limitSecondary br availSecondary $ limitSecondary br availSecondary
$ cropToContext prim $ cropToContext prim
renderHis (remainingPrimary - (result^.imageL.(to $ imagePrimary br))) let newRem = remainingPrimary - (result^.imageL.(to $ imagePrimary br))
(DL.snoc prev (i, result)) rest ((i, result) :) <$> renderHis newRem rest
renderedHis <- renderHis availPrimary DL.empty his renderedHis <- renderHis availPrimary his
renderedLows <- case lows of renderedLows <- case lows of
[] -> return [] [] -> return []