From cb79193effb61471611a2a540ca21d9dc21cf10d Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 11 Jan 2011 09:13:03 +0100 Subject: [PATCH] Don't perform a replace operation in Document.replace if there is nothing to replace. Increases performance in wrapMode if inserting many lines --- lib/ace/document.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/ace/document.js b/lib/ace/document.js index be1563a7..2138f234 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -688,6 +688,16 @@ var Document = function(text, mode) { }, this.replace = function(range, text) { + // Shortcut: Nothing to replace in this case. + if (text.length == 0 && range.isEmpty()) { + return range.start; + } else + // Shortcut: If the text we want to insert is the same as it is already + // in the document, we don't have to replace anything. + if (text == this.getTextRange(range)) { + return range.end; + } + this.$remove(range); if (text) { var end = this.$insert(range.start, text);