Permalink
Browse files

avoid useless recomputation of the display function in gtk frontend

At the cost of two list lookups, which is totally not worth it,
but I have a plan...
  • Loading branch information...
Mikolaj committed Apr 5, 2011
1 parent 5d5900b commit c89bea50228063eece5fb37aa7746c4527f8ab27
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/Display/Gtk.hs
View
@@ -100,10 +100,13 @@ display ((y0,x0), (y1,x1)) session f msg status =
postGUIAsync $
do
tb <- textViewGetBuffer (sview session)
- let text = unlines [ [ snd (f (y, x)) | x <- [x0..x1] ] | y <- [y0..y1] ]
- textBufferSetText tb (msg ++ "\n" ++ text ++ status)
- sequence_ [ setTo tb (stags session) (y, x) (fst (f (y, x))) |
- y <- [y0..y1], x <- [x0..x1]]
+ let memo = [ unzip [ f (y, x) | x <- [x0..x1] ] | y <- [y0..y1] ]
+ chars = L.map snd memo
+ attrs = L.map fst memo
+ atrrAt (y, x) = attrs L.!! (y - y0) L.!! (x - x0)
+ textBufferSetText tb (msg ++ "\n" ++ unlines chars ++ status)
+ sequence_ [ setTo tb (stags session) (y, x) (atrrAt (y, x))
+ | y <- [y0..y1], x <- [x0..x1]]
setTo :: TextBuffer -> Map Color.Attr TextTag -> Loc -> Color.Attr -> IO ()
setTo tb tts (ly, lx) a

0 comments on commit c89bea5

Please sign in to comment.