Changeset 52985 in webkit
- Timestamp:
- Jan 8, 2010 3:50:25 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r52974 r52985 1 2010-01-08 Pavel Feldman <pfeldman@chromium.org> 2 3 Reviewed by Timothy Hatcher. 4 5 Web Inspector: Regex-based syntax highlighting is slow. 6 7 https://bugs.webkit.org/show_bug.cgi?id=33330 8 9 * WebCore.gypi: 10 * WebCore.vcproj/WebCore.vcproj: 11 * inspector/front-end/JavaScriptHighlighterScheme.js: Removed. 12 * inspector/front-end/JavaScriptTokenizer.js: Added. 13 (WebInspector.JavaScriptTokenizer): 14 (WebInspector.JavaScriptTokenizer.prototype.set line): 15 (WebInspector.JavaScriptTokenizer.prototype.getCondition): 16 (WebInspector.JavaScriptTokenizer.prototype.setCondition): 17 (WebInspector.JavaScriptTokenizer.prototype._charAt): 18 (WebInspector.JavaScriptTokenizer.prototype.nextToken): 19 * inspector/front-end/JavaScriptTokenizer.re2js: Added. 20 * inspector/front-end/TextEditorHighlighter.js: 21 (WebInspector.TextEditorHighlighter): 22 (WebInspector.TextEditorHighlighter.prototype.highlight): 23 (WebInspector.TextEditorHighlighter.prototype._lex): 24 * inspector/front-end/WebKit.qrc: 25 * inspector/front-end/inspector.html: 26 1 27 2010-01-07 Mike Belshe <mbelshe@chromium.org> 2 28 -
trunk/WebCore/WebCore.gypi
r52949 r52985 3696 3696 'inspector/front-end/InjectedScriptAccess.js', 3697 3697 'inspector/front-end/inspector.js', 3698 'inspector/front-end/JavaScriptHighlighterScheme.js',3699 3698 'inspector/front-end/JavaScriptSourceSyntaxHighlighter.js', 3699 'inspector/front-end/JavaScriptTokenizer.js', 3700 3700 'inspector/front-end/KeyboardShortcut.js', 3701 3701 'inspector/front-end/MetricsSidebarPane.js', -
trunk/WebCore/WebCore.vcproj/WebCore.vcproj
r52949 r52985 42865 42865 </File> 42866 42866 <File 42867 RelativePath="..\inspector\front-end\JavaScriptHighlighterScheme.js"42868 >42869 </File>42870 <File42871 42867 RelativePath="..\inspector\front-end\JavaScriptSourceSyntaxHighlighter.js" 42868 > 42869 </File> 42870 <File 42871 RelativePath="..\inspector\front-end\JavaScriptTokenizer.js" 42872 42872 > 42873 42873 </File> -
trunk/WebCore/inspector/front-end/TextEditorHighlighter.js
r52945 r52985 33 33 { 34 34 this._textModel = textModel; 35 this._ highlighterScheme = new WebInspector.JavaScriptHighlighterScheme();35 this._tokenizer = new WebInspector.JavaScriptTokenizer(); 36 36 37 37 this._styles = []; 38 this._styles[WebInspector.TextEditorHighlighter.TokenType.Comment] = "rgb(0, 116, 0)"; 39 this._styles[WebInspector.TextEditorHighlighter.TokenType.String] = "rgb(196, 26, 22)"; 40 this._styles[WebInspector.TextEditorHighlighter.TokenType.Keyword] = "rgb(170, 13, 145)"; 41 this._styles[WebInspector.TextEditorHighlighter.TokenType.Number] = "rgb(28, 0, 207)"; 42 } 43 44 WebInspector.TextEditorHighlighter.TokenType = { 45 Comment: 0, 46 String: 1, 47 Keyword: 2, 48 Number: 3 38 this._styles["comment"] = "rgb(0, 116, 0)"; 39 this._styles["string"] = "rgb(196, 26, 22)"; 40 this._styles["regex"] = "rgb(196, 26, 22)"; 41 this._styles["keyword"] = "rgb(170, 13, 145)"; 42 this._styles["number"] = "rgb(28, 0, 207)"; 49 43 } 50 44 … … 52 46 highlight: function(startLine, endLine) 53 47 { 54 this._highlighterScheme.reset(this);55 48 // Rewind to the last highlighted line to gain proper highlighter context. 56 49 while (startLine > 0 && !this._textModel.getAttribute(startLine - 1, 0, "highlighter-state")) … … 59 52 // Restore highlighter context taken from previous line. 60 53 var state = this._textModel.getAttribute(startLine - 1, 0, "highlighter-state"); 61 if (state) { 62 this.continueState = state.postContinueState; 63 this.lexState = state.postLexState; 64 } 65 54 if (state) 55 this._tokenizer.condition = state.postCondition; 56 else 57 this._tokenizer.condition = this._tokenizer.initialCondition; 66 58 // Each line has associated state attribute with pre- and post-highlighter conditions. 67 59 // Highlight lines from range until we find line precondition matching highlighter state. … … 69 61 for (var i = startLine; i < endLine; ++i) { 70 62 state = this._textModel.getAttribute(i, 0, "highlighter-state"); 71 if (state && state.preCon tinueState === this.continueState && state.preLexState === this.lexState) {63 if (state && state.preCondition === this._tokenizer.condition) { 72 64 // Following lines are up to date, no need re-highlight. 73 this.continueState = state.postContinueState; 74 this.lexState = state.postLexState; 65 this._tokenizer.condition = state.postCondition; 75 66 continue; 76 67 } … … 79 70 80 71 state = {}; 81 state.preContinueState = this.continueState; 82 state.preLexState = this.lexState; 72 state.preCondition = this._tokenizer.condition; 83 73 84 74 this._textModel.removeAttributes(i, "highlight"); 85 var line = this._textModel.line(i); 86 for (var j = 0; j < line.length;) 87 j += this._lex(line.substring(j), i, j); 75 this._lex(this._textModel.line(i), i); 88 76 89 state.postContinueState = this.continueState; 90 state.postLexState = this.lexState; 77 state.postCondition = this._tokenizer.condition; 91 78 this._textModel.addAttribute(i, 0, "highlighter-state", state); 92 79 } … … 94 81 state = this._textModel.getAttribute(endLine, 0, "highlighter-state"); 95 82 96 if (state && (state.preContinueState !== this.continueState || state.preLexState !== this.lexState)) {83 if (state && state.preCondition !== this._tokenizer.condition) { 97 84 // Requested highlight range is over, but we did not recover. Invalidate tail highlighting. 98 85 for (var i = endLine; i < this._textModel.linesCount; ++i) 99 86 this._textModel.removeAttributes(i, "highlighter-state"); 100 87 } 101 102 88 return damage; 103 89 }, 104 90 105 _lex: function(codeFragment, line, column) { 106 var token = null; 107 for (var i = 0; i < this._highlighterScheme.rules.length; i++) { 108 var rule = this._highlighterScheme.rules[i]; 109 var ruleContinueStateCondition = typeof rule.preContinueState !== "undefined" ? rule.preContinueState : this._highlighterScheme.ContinueState.None; 110 if (this.continueState !== ruleContinueStateCondition) 111 continue; 112 if (typeof rule.preLexState !== "undefined" && this.lexState !== rule.preLexState) 113 continue; 114 115 var match = rule.pattern.exec(codeFragment); 116 if (match) { 117 token = match[0]; 118 if (token && (!rule.keywords || (token in rule.keywords))) { 119 if (typeof rule.type === "number") 120 this._textModel.addAttribute(line, column, "highlight", { length: token.length, style: this._styles[rule.type] }); 121 if (typeof rule.postLexState !== "undefined") 122 this.lexState = rule.postLexState; 123 if (typeof rule.postContinueState !== "undefined") 124 this.continueState = rule.postContinueState; 125 return token.length; 126 } 127 } 128 } 129 return 1; 91 _lex: function(line, lineNumber) { 92 this._tokenizer.line = line; 93 var column = 0; 94 do { 95 var newColumn = this._tokenizer.nextToken(column); 96 var tokenType = this._tokenizer.tokenType; 97 if (tokenType) 98 this._textModel.addAttribute(lineNumber, column, "highlight", { length: newColumn - column, style: this._styles[tokenType] }); 99 column = newColumn; 100 } while (column < line.length) 130 101 } 131 102 } -
trunk/WebCore/inspector/front-end/WebKit.qrc
r52945 r52985 36 36 <file>InspectorBackendStub.js</file> 37 37 <file>InspectorFrontendHostStub.js</file> 38 <file>JavaScriptHighlighterScheme.js</file>39 38 <file>JavaScriptSourceSyntaxHighlighter.js</file> 39 <file>JavaScriptTokenizer.js</file> 40 40 <file>KeyboardShortcut.js</file> 41 41 <file>MetricsSidebarPane.js</file> -
trunk/WebCore/inspector/front-end/inspector.html
r52945 r52985 98 98 <script type="text/javascript" src="TextEditor.js"></script> 99 99 <script type="text/javascript" src="TextEditorHighlighter.js"></script> 100 <script type="text/javascript" src="JavaScript HighlighterScheme.js"></script>100 <script type="text/javascript" src="JavaScriptTokenizer.js"></script> 101 101 <script type="text/javascript" src="SourceView.js"></script> 102 102 <script type="text/javascript" src="FontView.js"></script>
Note: See TracChangeset
for help on using the changeset viewer.