Web Inspector: introduce fast case for within-chunk edit
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2012 20:06:37 +0000 (20:06 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2012 20:06:37 +0000 (20:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103545

Reviewed by Vsevolod Vlasov.

Special-casing edits within the chunk for faster operation.

* inspector/front-end/DOMExtension.js:
(removeSubsequentNodes):
* inspector/front-end/DefaultTextEditor.js:
(WebInspector.TextEditorMainPanel.prototype._updateChunksForRanges):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@136145 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/DOMExtension.js
Source/WebCore/inspector/front-end/DefaultTextEditor.js

index 55ef763..92cc8c7 100644 (file)
@@ -1,5 +1,19 @@
 2012-11-29  Pavel Feldman  <pfeldman@chromium.org>
 
+        Web Inspector: introduce fast case for within-chunk edit
+        https://bugs.webkit.org/show_bug.cgi?id=103545
+
+        Reviewed by Vsevolod Vlasov.
+
+        Special-casing edits within the chunk for faster operation.
+
+        * inspector/front-end/DOMExtension.js:
+        (removeSubsequentNodes):
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.TextEditorMainPanel.prototype._updateChunksForRanges):
+
+2012-11-29  Pavel Feldman  <pfeldman@chromium.org>
+
         Web Inspector: Console: hovering node wrappers in object tree should highlight them on the page
         https://bugs.webkit.org/show_bug.cgi?id=101150
 
index 162fa96..5bfcd22 100644 (file)
@@ -195,6 +195,18 @@ Element.prototype.remove = function()
         this.parentElement.removeChild(this);
 }
 
+/**
+ * @param {Node} fromNode
+ * @param {Node} toNode
+ */
+function removeSubsequentNodes(fromNode, toNode)
+{
+    for (var node = fromNode; node && node !== toNode; ) {
+        var nodeToRemove = node;
+        node = node.nextSibling;
+        nodeToRemove.remove();
+    }
+}
 
 /**
  * @constructor
index 08f48e0..458e545 100644 (file)
@@ -2415,13 +2415,28 @@ WebInspector.TextEditorMainPanel.prototype = {
         // Remove damaged chunks from DOM and from textChunks model.
         var lastUndamagedChunk = firstDamagedChunkNumber > 0 ? this._textChunks[firstDamagedChunkNumber - 1] : null;
         var firstUndamagedChunk = lastDamagedChunkNumber + 1 < this._textChunks.length ? this._textChunks[lastDamagedChunkNumber + 1] : null;
+
         var removeDOMFromNode = lastUndamagedChunk ? lastUndamagedChunk.lastElement().nextSibling : this._container.firstChild;
         var removeDOMToNode = firstUndamagedChunk ? firstUndamagedChunk.firstElement() : null;
-        for (var node = removeDOMFromNode; node && node !== removeDOMToNode; ) {
-            var nodeToRemove = node;
-            node = node.nextSibling;
-            nodeToRemove.remove();
+
+        // Fast case - patch single expanded chunk that did not grow / shrink during edit.
+        if (!linesDiff && firstDamagedChunk === lastDamagedChunk && firstDamagedChunk._expandedLineRows) {
+            var lastUndamagedLineRow = lastDamagedChunk.expandedLineRow(oldRange.startLine - 1);
+            var firstUndamagedLineRow = firstDamagedChunk.expandedLineRow(oldRange.endLine + 1);
+            var localRemoveDOMFromNode = lastUndamagedLineRow ? lastUndamagedLineRow.nextSibling : removeDOMFromNode;
+            var localRemoveDOMToNode = firstUndamagedLineRow || removeDOMToNode;
+            removeSubsequentNodes(localRemoveDOMFromNode, localRemoveDOMToNode);
+            for (var i = newRange.startLine; i < newRange.endLine + 1; ++i) {
+                var row = firstDamagedChunk._createRow(i);
+                firstDamagedChunk._expandedLineRows[i - firstDamagedChunk.startLine] = row;
+                this._container.insertBefore(row, localRemoveDOMToNode);
+            }
+            firstDamagedChunk.updateCollapsedLineRow();
+            this._assertDOMMatchesTextModel();
+            return;
         }
+
+        removeSubsequentNodes(removeDOMFromNode, removeDOMToNode);
         this._textChunks.splice(firstDamagedChunkNumber, lastDamagedChunkNumber - firstDamagedChunkNumber + 1);
 
         // Compute damaged chunks span