Title: [90209] trunk
- Revision
- 90209
- Author
- [email protected]
- Date
- 2011-06-30 23:50:14 -0700 (Thu, 30 Jun 2011)
Log Message
2011-06-30 Eugene Klyuchnikov <[email protected]>
Reviewed by Pavel Feldman.
WebInspector: Performance / memory allocation issue in WebInspector.TextEditorModel.prototype._replaceTabsIfNeeded
https://bugs.webkit.org/show_bug.cgi?id=40447
* inspector/editor/text-editor-model-replace-tabs-expected.txt: Added.
* inspector/editor/text-editor-model-replace-tabs.html: Added.
2011-06-30 Eugene Klyuchnikov <[email protected]>
Reviewed by Pavel Feldman.
WebInspector: Performance / memory allocation issue in WebInspector.TextEditorModel.prototype._replaceTabsIfNeeded
https://bugs.webkit.org/show_bug.cgi?id=40447
Test: inspector/editor/text-editor-model-replace-tabs.html
* inspector/front-end/TextEditorModel.js:
(WebInspector.TextEditorModel.prototype._replaceTabsIfNeeded): avoid looped production of tail substrings
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (90208 => 90209)
--- trunk/LayoutTests/ChangeLog 2011-07-01 06:36:07 UTC (rev 90208)
+++ trunk/LayoutTests/ChangeLog 2011-07-01 06:50:14 UTC (rev 90209)
@@ -1,3 +1,13 @@
+2011-06-30 Eugene Klyuchnikov <[email protected]>
+
+ Reviewed by Pavel Feldman.
+
+ WebInspector: Performance / memory allocation issue in WebInspector.TextEditorModel.prototype._replaceTabsIfNeeded
+ https://bugs.webkit.org/show_bug.cgi?id=40447
+
+ * inspector/editor/text-editor-model-replace-tabs-expected.txt: Added.
+ * inspector/editor/text-editor-model-replace-tabs.html: Added.
+
2011-06-30 Kent Tamura <[email protected]>
[Chromium] Update test expectations.
Added: trunk/LayoutTests/inspector/editor/text-editor-model-replace-tabs-expected.txt (0 => 90209)
--- trunk/LayoutTests/inspector/editor/text-editor-model-replace-tabs-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-model-replace-tabs-expected.txt 2011-07-01 06:50:14 UTC (rev 90209)
@@ -0,0 +1,48 @@
+This test checks the text editor model _replaceTabsIfNeeded method. In test cases tabulations are denoted with "\t" and spaces are rendered as ".";
+
+Test Case #0
+Input:
+Output:
+
+Test Case #1
+Input: \t
+Output: ....
+
+Test Case #2
+Input: A\t
+Output: A...
+
+Test Case #3
+Input: AB\t
+Output: AB..
+
+Test Case #4
+Input: ABC\t
+Output: ABC.
+
+Test Case #5
+Input: \tA
+Output: ....A
+
+Test Case #6
+Input: A\tB
+Output: A...B
+
+Test Case #7
+Input: \t\tA\t
+Output: ........A...
+
+Test Case #8
+Input: \tA\t\t
+Output: ....A.......
+
+Test Case #9
+Input: A
+Output: A
+
+Test Case #10
+Input: \tABCD
+Output: ....ABCD
+
+Very Long test: PASS
+
Added: trunk/LayoutTests/inspector/editor/text-editor-model-replace-tabs.html (0 => 90209)
--- trunk/LayoutTests/inspector/editor/text-editor-model-replace-tabs.html (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-model-replace-tabs.html 2011-07-01 06:50:14 UTC (rev 90209)
@@ -0,0 +1,46 @@
+<html>
+<head>
+<script src=""
+<script>
+
+function test()
+{
+ var textModel = new WebInspector.TextEditorModel();
+ textModel.replaceTabsWithSpaces = true;
+ var testCases = new Array("","\t","A\t","AB\t","ABC\t","\tA","A\tB","\t\tA\t","\tA\t\t","A","\tABCD");
+ for (var i = 0; i < testCases.length; i++) {
+ var input = testCases[i];
+ var output = new Array(input);
+ textModel._replaceTabsIfNeeded(output);
+ output = output[0];
+ InspectorTest.addResult("Test Case #" + i);
+ InspectorTest.addResult("Input: " + input.replace(/\t/g, "\\t").replace(/ /g, "."));
+ InspectorTest.addResult("Output: " + output.replace(/\t/g, "\\t").replace(/ /g, "."));
+ InspectorTest.addResult("");
+ }
+
+ var input = [];
+ var output = [];
+ for (var i = 0; i < 10000; i++) {
+ input.push("\t\t\t\t\t\t\t\t\t\t"); // 10 tabulations
+ output.push(" "); // 40 spaces
+ }
+ input = new Array(input.join(""));
+ output = output.join("");
+ textModel._replaceTabsIfNeeded(input);
+ var correctResult = (input[0] === output);
+ InspectorTest.addResult("Very Long test: " + (correctResult ? "PASS" : "FAIL"));
+
+ InspectorTest.completeTest();
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+This test checks the text editor model _replaceTabsIfNeeded method.
+In test cases tabulations are denoted with "\t" and spaces are rendered as ".";
+</p>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (90208 => 90209)
--- trunk/Source/WebCore/ChangeLog 2011-07-01 06:36:07 UTC (rev 90208)
+++ trunk/Source/WebCore/ChangeLog 2011-07-01 06:50:14 UTC (rev 90209)
@@ -1,3 +1,15 @@
+2011-06-30 Eugene Klyuchnikov <[email protected]>
+
+ Reviewed by Pavel Feldman.
+
+ WebInspector: Performance / memory allocation issue in WebInspector.TextEditorModel.prototype._replaceTabsIfNeeded
+ https://bugs.webkit.org/show_bug.cgi?id=40447
+
+ Test: inspector/editor/text-editor-model-replace-tabs.html
+
+ * inspector/front-end/TextEditorModel.js:
+ (WebInspector.TextEditorModel.prototype._replaceTabsIfNeeded): avoid looped production of tail substrings
+
2011-06-30 Kent Tamura <[email protected]>
Reviewed by Tony Chang.
Modified: trunk/Source/WebCore/inspector/front-end/TextEditorModel.js (90208 => 90209)
--- trunk/Source/WebCore/inspector/front-end/TextEditorModel.js 2011-07-01 06:36:07 UTC (rev 90208)
+++ trunk/Source/WebCore/inspector/front-end/TextEditorModel.js 2011-07-01 06:50:14 UTC (rev 90209)
@@ -146,12 +146,24 @@
var spaces = [ " ", " ", " ", " "];
for (var i = 0; i < lines.length; ++i) {
var line = lines[i];
- var index = line.indexOf("\t");
+ var caretIndex = 0;
+ var index = line.indexOf("\t", caretIndex);
+ var buffer = [];
+ var offset = 0;
while (index !== -1) {
- line = line.substring(0, index) + spaces[index % 4] + line.substring(index + 1);
- index = line.indexOf("\t", index + 1);
+ if (index > caretIndex) {
+ offset += index - caretIndex;
+ buffer.push(line.substring(caretIndex, index));
+ }
+ caretIndex = index + 1;
+ var space = spaces[offset % 4];
+ offset += space.length;
+ buffer.push(space);
+ index = line.indexOf("\t", caretIndex);
}
- lines[i] = line;
+ if (line.length > caretIndex)
+ buffer.push(line.substring(caretIndex));
+ lines[i] = buffer.join("");
}
},
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes