memoize Buffer @contentOnDisk so we don't re-read the whole file on every buffer-change event

This commit is contained in:
Will Farrington 2012-10-08 18:17:15 -10:00
parent 4b3505d9b5
commit d5b0e7acd2

View File

@ -14,6 +14,7 @@ class Buffer
@idCounter = 1
undoManager: null
modified: null
contentOnDisk: null
modifiedOnDisk: null
lines: null
file: null
@ -30,7 +31,8 @@ class Buffer
if path
throw "Path '#{path}' does not exist" unless fs.exists(path)
@setPath(path)
@setText(fs.read(@getPath()))
@contentOnDisk = fs.read(@getPath())
@setText(@contentOnDisk)
else
@setText('')
@ -68,7 +70,8 @@ class Buffer
@trigger "path-change", this
reload: ->
@setText(fs.read(@file.getPath()))
@contentOnDisk = fs.read(@getPath())
@setText(@contentOnDisk)
@modified = false
@modifiedOnDisk = false
@ -236,6 +239,7 @@ class Buffer
@modified = false
@modifiedOnDisk = false
@setPath(path)
@contentOnDisk = @getText()
@trigger 'after-save'
@trigger 'buffer-change'
@ -249,7 +253,7 @@ class Buffer
@modified
contentDifferentOnDisk: ->
fs.read(@file.getPath()) != @getText()
@contentOnDisk != @getText()
getAnchors: -> new Array(@anchors...)