mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-08 16:19:17 +03:00
memoize Buffer @contentOnDisk so we don't re-read the whole file on every buffer-change event
This commit is contained in:
parent
4b3505d9b5
commit
d5b0e7acd2
@ -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...)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user