Bring back brush caching

openid
Marcin Kulik 12 years ago
parent cce80b07ca
commit 0b01d98db2

@ -1,4 +1,9 @@
class AsciiIo.Brush
@cache: {}
@clearCache: ->
@cache = {}
@defaultAttrs =
fg : undefined
bg : undefined
@ -8,11 +13,21 @@ class AsciiIo.Brush
underline: false
@default: ->
@_default ||= new AsciiIo.Brush()
@_default ||= @create()
@hash: (brush) ->
"#{brush.fg}_#{brush.bg}_#{brush.bright}_#{brush.underline}_#{brush.italic}_#{brush.blink}"
@create: (options = {}) ->
key = @hash options
brush = @cache[key]
if not brush
brush = new AsciiIo.Brush(options)
@cache[key] = brush
brush
constructor: (options = {}) ->
_(this).extend AsciiIo.Brush.defaultAttrs, options

@ -38,7 +38,7 @@ class AsciiIo.Renderer.Canvas extends AsciiIo.Renderer.Base
for fragment in fragments
[text, brush] = fragment
brush = new AsciiIo.Brush(brush) if brush
brush = AsciiIo.Brush.create brush if brush
if cursorX isnt undefined and rendered <= cursorX < rendered + text.length
@cursorBrush = brush

@ -58,7 +58,7 @@ class AsciiIo.Renderer.Pre extends AsciiIo.Renderer.Base
text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
spanFromBrush: (brush) ->
brush = new AsciiIo.Brush brush
brush = AsciiIo.Brush.create brush
key = brush.hash()
span = @cachedSpans[key]

@ -246,7 +246,7 @@ class AsciiIo.ScreenBuffer
updateBrush: (changes) ->
attrs = _.extend({}, @brush.attributes(), changes)
@brush = new AsciiIo.Brush attrs
@brush = AsciiIo.Brush.create attrs
# ----- Scroll control

Loading…
Cancel
Save