- Revision
- 138438
- Author
- [email protected]
- Date
- 2012-12-24 03:23:07 -0800 (Mon, 24 Dec 2012)
Log Message
Web Inspector: refactor TextEditorHighlighter's highlight attributes to dense array
https://bugs.webkit.org/show_bug.cgi?id=105626
Patch by Andrey Lushnikov <[email protected]> on 2012-12-24
Reviewed by Pavel Feldman.
Source/WebCore:
Refactor highlight attributes from sparse array to dense array.
No new tests: no behaviour changes, coverage provided by existing tests.
* inspector/front-end/DefaultTextEditor.js:
(WebInspector.TextEditorMainPanel.prototype._paintLine):
(WebInspector.TextEditorMainPanel.prototype._closingBlockOffset):
* inspector/front-end/TextEditorHighlighter.js:
(WebInspector.TextEditorHighlighter.prototype._highlightLines):
LayoutTests:
Fix tests according to new highlight attribute structure.
* inspector/editor/highlighter-long-line.html:
* inspector/editor/highlighter-test.js:
(initialize_HighlighterTests.InspectorTest.dumpTextModel):
(initialize_HighlighterTests):
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (138437 => 138438)
--- trunk/LayoutTests/ChangeLog 2012-12-24 10:03:39 UTC (rev 138437)
+++ trunk/LayoutTests/ChangeLog 2012-12-24 11:23:07 UTC (rev 138438)
@@ -1,3 +1,17 @@
+2012-12-24 Andrey Lushnikov <[email protected]>
+
+ Web Inspector: refactor TextEditorHighlighter's highlight attributes to dense array
+ https://bugs.webkit.org/show_bug.cgi?id=105626
+
+ Reviewed by Pavel Feldman.
+
+ Fix tests according to new highlight attribute structure.
+
+ * inspector/editor/highlighter-long-line.html:
+ * inspector/editor/highlighter-test.js:
+ (initialize_HighlighterTests.InspectorTest.dumpTextModel):
+ (initialize_HighlighterTests):
+
2012-12-23 Zan Dobersek <[email protected]>
Unreviewed GTK gardening.
Modified: trunk/LayoutTests/inspector/editor/highlighter-long-line.html (138437 => 138438)
--- trunk/LayoutTests/inspector/editor/highlighter-long-line.html 2012-12-24 10:03:39 UTC (rev 138437)
+++ trunk/LayoutTests/inspector/editor/highlighter-long-line.html 2012-12-24 11:23:07 UTC (rev 138438)
@@ -25,14 +25,14 @@
var commentsFound = 0;
for (var lineNumber = 0; lineNumber < textModel.linesCount; ++lineNumber) {
var highlight = textModel.getAttribute(lineNumber, "highlight");
- for (var i = 0; i < textModel.lineLength(lineNumber); ++i) {
- if (highlight[i]) {
- if (highlight[i].length !== 10 || (i % 11)) {
- InspectorTest.addResult("ERROR: unexpected highlight result: i=" + i + ", length=" + highlight[i].length);
- break;
- }
- ++commentsFound;
+ for (var i = 0; i < highlight.ranges.length; ++i) {
+ const range = highlight.ranges[i];
+ const rangeLength = range.endColumn - range.startColumn + 1;
+ if (rangeLength !== 10 || (range.startColumn % 11)) {
+ InspectorTest.addResult("ERROR: unexpected highlight result: i=" + range.startColumn + ", length=" + rangeLength);
+ break;
}
+ ++commentsFound;
}
}
if (comments !== commentsFound)
Modified: trunk/LayoutTests/inspector/editor/highlighter-test.js (138437 => 138438)
--- trunk/LayoutTests/inspector/editor/highlighter-test.js 2012-12-24 10:03:39 UTC (rev 138437)
+++ trunk/LayoutTests/inspector/editor/highlighter-test.js 2012-12-24 11:23:07 UTC (rev 138438)
@@ -9,9 +9,10 @@
var highlight = textModel.getAttribute(i, "highlight");
var result = (i + 1) + " : " + line + " :";
if (highlight) {
- for (var j = 0; j < line.length; ++j)
- if (highlight[j])
- result += " " + highlight[j].tokenType + "[" + j + "-" + (j + highlight[j].length) + "]";
+ for (var j = 0; j < highlight.ranges.length; ++j) {
+ var range = highlight.ranges[j];
+ result += " " + range.token + "[" + range.startColumn + "-" + (range.endColumn + 1) + "]";
+ }
} else
result += " null";
lines.push(result);
Modified: trunk/Source/WebCore/ChangeLog (138437 => 138438)
--- trunk/Source/WebCore/ChangeLog 2012-12-24 10:03:39 UTC (rev 138437)
+++ trunk/Source/WebCore/ChangeLog 2012-12-24 11:23:07 UTC (rev 138438)
@@ -1,3 +1,20 @@
+2012-12-24 Andrey Lushnikov <[email protected]>
+
+ Web Inspector: refactor TextEditorHighlighter's highlight attributes to dense array
+ https://bugs.webkit.org/show_bug.cgi?id=105626
+
+ Reviewed by Pavel Feldman.
+
+ Refactor highlight attributes from sparse array to dense array.
+
+ No new tests: no behaviour changes, coverage provided by existing tests.
+
+ * inspector/front-end/DefaultTextEditor.js:
+ (WebInspector.TextEditorMainPanel.prototype._paintLine):
+ (WebInspector.TextEditorMainPanel.prototype._closingBlockOffset):
+ * inspector/front-end/TextEditorHighlighter.js:
+ (WebInspector.TextEditorHighlighter.prototype._highlightLines):
+
2012-12-21 Alexander Pavlov <[email protected]>
Web Inspector: Make use of the new InspectorState::remove() in inspector agents
Modified: trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js (138437 => 138438)
--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js 2012-12-24 10:03:39 UTC (rev 138437)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js 2012-12-24 11:23:07 UTC (rev 138438)
@@ -1774,8 +1774,8 @@
},
/**
- * @param {number} fromLine
- * @param {number} toLine
+ * @param {number} fromLine inclusive
+ * @param {number} toLine exclusive
* @param {boolean=} restoreSelection
*/
_paintLines: function(fromLine, toLine, restoreSelection)
@@ -1863,34 +1863,26 @@
}
var line = this._textModel.line(lineNumber);
+ var ranges = this._highlighter.orderedRangesPerLine(lineNumber);
+
if (!line)
lineRow.insertBefore(document.createElement("br"), decorationsElement);
- var plainTextStart = -1;
- for (var j = 0; j < line.length;) {
- if (j > 1000) {
- // This line is too long - do not waste cycles on minified js highlighting.
- if (plainTextStart === -1)
- plainTextStart = j;
- break;
- }
- var attribute = highlight[j];
- if (!attribute || !attribute.tokenType) {
- if (plainTextStart === -1)
- plainTextStart = j;
- j++;
- } else {
- if (plainTextStart !== -1) {
- this._insertTextNodeBefore(lineRow, decorationsElement, line.substring(plainTextStart, j));
- plainTextStart = -1;
- --this._paintLinesOperationsCredit;
- }
- this._insertSpanBefore(lineRow, decorationsElement, line.substring(j, j + attribute.length), attribute.tokenType);
- j += attribute.length;
+ var plainTextStart = 0;
+ for(var i = 0; i < ranges.length; i++) {
+ var rangeStart = ranges[i].startColumn;
+ var rangeEnd = ranges[i].endColumn;
+ var rangeToken = ranges[i].token;
+
+ if (plainTextStart < rangeStart) {
+ this._insertTextNodeBefore(lineRow, decorationsElement, line.substring(plainTextStart, rangeStart));
--this._paintLinesOperationsCredit;
}
+ this._insertSpanBefore(lineRow, decorationsElement, line.substring(rangeStart, rangeEnd + 1), rangeToken);
+ --this._paintLinesOperationsCredit;
+ plainTextStart = rangeEnd + 1;
}
- if (plainTextStart !== -1) {
+ if (plainTextStart < line.length) {
this._insertTextNodeBefore(lineRow, decorationsElement, line.substring(plainTextStart, line.length));
--this._paintLinesOperationsCredit;
}
@@ -2362,16 +2354,16 @@
var attribute = this._textModel.getAttribute(i, "highlight");
if (!attribute)
continue;
- var columnNumbers = Object.keys(attribute).reverse();
- for (var j = 0; j < columnNumbers.length; ++j) {
- var column = columnNumbers[j];
- if (attribute[column].tokenType === "block-start") {
+ var ranges = attribute.ranges;
+ for (var j = ranges.length - 1; j >= 0; j--) {
+ var token = ranges[j].token;
+ if (token === "block-start") {
if (!(--nestingLevel)) {
var lineContent = this._textModel.line(i);
return lineContent.length - lineContent.trimLeft().length;
}
}
- if (attribute[column].tokenType === "block-end")
+ if (token === "block-end")
++nestingLevel;
}
}
Modified: trunk/Source/WebCore/inspector/front-end/TextEditorHighlighter.js (138437 => 138438)
--- trunk/Source/WebCore/inspector/front-end/TextEditorHighlighter.js 2012-12-24 10:03:39 UTC (rev 138437)
+++ trunk/Source/WebCore/inspector/front-end/TextEditorHighlighter.js 2012-12-24 11:23:07 UTC (rev 138438)
@@ -56,6 +56,23 @@
},
/**
+ * @param {number} lineNumber
+ * @return {Array.<{startColumn: number, endColumn: number, token: string}>}
+ */
+ orderedRangesPerLine: function(lineNumber)
+ {
+ var syntaxTokenHighligh = this._textModel.getAttribute(lineNumber, "highlight");
+ if (!syntaxTokenHighligh)
+ return [];
+
+ syntaxTokenHighligh.ranges.sort(function(a, b) {
+ return a.startColumn - b.startColumn;
+ });
+
+ return syntaxTokenHighligh.ranges;
+ },
+
+ /**
* @param {boolean=} forceRun
*/
highlight: function(endLine, forceRun)
@@ -175,11 +192,16 @@
this._tokenizer.condition = JSON.parse(postConditionStringified);
// Highlight line.
+ state.ranges = [];
do {
var newColumn = this._tokenizer.nextToken(lastHighlightedColumn);
var tokenType = this._tokenizer.tokenType;
if (tokenType)
- state[lastHighlightedColumn] = { length: newColumn - lastHighlightedColumn, tokenType: tokenType };
+ state.ranges.push({
+ startColumn: lastHighlightedColumn,
+ endColumn: newColumn - 1,
+ token: tokenType
+ });
lastHighlightedColumn = newColumn;
if (++tokensCount > this._highlightChunkLimit)
break;