on master help sign in
I'm reasonably sure we can use unsafeWrite O_O
f224ab1Corey O'Connor
src/Graphics/Vty/Span.hs+7−7
@@ -254,24 +254,24 @@ snoc_text_span :: Attr -- the display attributes of the text span
254 -- defined to the end of the display for the row.
254 -- defined to the end of the display for the row.
255 -> ST s Word
255 -> ST s Word
256snoc_text_span a text_str mrow_ops columns_to_skip y remaining_columns = do
256snoc_text_span a text_str mrow_ops columns_to_skip y remaining_columns = do
257− snoc_op mrow_ops y $ AttributeChange a
257+ {-# SCC "snoc_text_span-pre" #-} snoc_op mrow_ops y $! AttributeChange a
258 -- At most a text span will consist of remaining_columns characters
258 -- At most a text span will consist of remaining_columns characters
259 -- we keep track of the position of the next character.
259 -- we keep track of the position of the next character.
260 let max_len :: Int = fromEnum remaining_columns
260 let max_len :: Int = fromEnum remaining_columns
261 mspan_chars <- Vector.new max_len
261 mspan_chars <- Vector.new max_len
262 ( used_display_columns, display_columns_skipped, used_char_count )
262 ( used_display_columns, display_columns_skipped, used_char_count )
263− <- Foldable.foldlM (build_text_span mspan_chars) ( 0, 0, 0 ) text_str
263+ <- {-# SCC "snoc_text_span-foldlM" #-} Foldable.foldlM (build_text_span mspan_chars) ( 0, 0, 0 ) text_str
264 -- once all characters have been output to mspan_chars we grab the used head
264 -- once all characters have been output to mspan_chars we grab the used head
265 out_text <- Vector.unsafeFreeze $! Vector.take used_char_count mspan_chars
265 out_text <- Vector.unsafeFreeze $! Vector.take used_char_count mspan_chars
266 -- convert to UTF8 bytestring.
266 -- convert to UTF8 bytestring.
267 -- This could be made faster. Hopefully the optimizer does a fair job at fusing the fold
267 -- This could be made faster. Hopefully the optimizer does a fair job at fusing the fold
268 -- contained in fromString with the unfold in toList. No biggy right now then.
268 -- contained in fromString with the unfold in toList. No biggy right now then.
269− snoc_op mrow_ops y $! TextSpan used_display_columns (toEnum used_char_count)
269+ {-# SCC "snoc_text_span-post" #-} snoc_op mrow_ops y $! TextSpan used_display_columns (toEnum used_char_count)
270 $! UTF8.fromString
270 $! UTF8.fromString
271 $! Vector.toList out_text
271 $! Vector.toList out_text
272 return $ columns_to_skip - display_columns_skipped
272 return $ columns_to_skip - display_columns_skipped
273 where
273 where
274− build_text_span mspan_chars (used_display_columns, display_columns_skipped, used_char_count)
274+ build_text_span mspan_chars (!used_display_columns, !display_columns_skipped, !used_char_count)
275 (out_char, char_display_width) = {-# SCC "build_text_span" #-}
275 (out_char, char_display_width) = {-# SCC "build_text_span" #-}
276 -- Only valid if the maximum width of a character is 2 display columns.
276 -- Only valid if the maximum width of a character is 2 display columns.
277 -- XXX: Optimize into a skip pass then clipped fill pass
277 -- XXX: Optimize into a skip pass then clipped fill pass
@@ -280,20 +280,20 @@ snoc_text_span a text_str mrow_ops columns_to_skip y remaining_columns = do
280 then return $! ( used_display_columns, display_columns_skipped, used_char_count )
280 then return $! ( used_display_columns, display_columns_skipped, used_char_count )
281 else if ( used_display_columns + char_display_width ) > remaining_columns
281 else if ( used_display_columns + char_display_width ) > remaining_columns
282 then do
282 then do
283− Vector.write mspan_chars used_char_count '…'
283+ Vector.unsafeWrite mspan_chars used_char_count '…'
284 return $! ( used_display_columns
284 return $! ( used_display_columns
285 , display_columns_skipped
285 , display_columns_skipped
286 , used_char_count + 1
286 , used_char_count + 1
287 )
287 )
288 else do
288 else do
289− Vector.write mspan_chars used_char_count out_char
289+ Vector.unsafeWrite mspan_chars used_char_count out_char
290 return $! ( used_display_columns + char_display_width
290 return $! ( used_display_columns + char_display_width
291 , display_columns_skipped
291 , display_columns_skipped
292 , used_char_count + 1
292 , used_char_count + 1
293 )
293 )
294 else if (display_columns_skipped + char_display_width) > columns_to_skip
294 else if (display_columns_skipped + char_display_width) > columns_to_skip
295 then do
295 then do
296− Vector.write mspan_chars used_char_count '…'
296+ Vector.unsafeWrite mspan_chars used_char_count '…'
297 return $! ( used_display_columns + 1
297 return $! ( used_display_columns + 1
298 , columns_to_skip
298 , columns_to_skip
299 , used_char_count + 1
299 , used_char_count + 1