From d5b0e7acd2f542f677ec6f1a40d4d4e675d42121 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Mon, 8 Oct 2012 18:17:15 -1000 Subject: [PATCH] memoize Buffer @contentOnDisk so we don't re-read the whole file on every buffer-change event --- src/app/buffer.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/buffer.coffee b/src/app/buffer.coffee index ccf5f255b..ef4468efd 100644 --- a/src/app/buffer.coffee +++ b/src/app/buffer.coffee @@ -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...)