Changeset 52985 in webkit


Ignore:
Timestamp:
Jan 8, 2010 3:50:25 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2010-01-08 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: Regex-based syntax highlighting is slow.

https://bugs.webkit.org/show_bug.cgi?id=33330

  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • inspector/front-end/JavaScriptHighlighterScheme.js: Removed.
  • inspector/front-end/JavaScriptTokenizer.js: Added. (WebInspector.JavaScriptTokenizer): (WebInspector.JavaScriptTokenizer.prototype.set line): (WebInspector.JavaScriptTokenizer.prototype.getCondition): (WebInspector.JavaScriptTokenizer.prototype.setCondition): (WebInspector.JavaScriptTokenizer.prototype._charAt): (WebInspector.JavaScriptTokenizer.prototype.nextToken):
  • inspector/front-end/JavaScriptTokenizer.re2js: Added.
  • inspector/front-end/TextEditorHighlighter.js: (WebInspector.TextEditorHighlighter): (WebInspector.TextEditorHighlighter.prototype.highlight): (WebInspector.TextEditorHighlighter.prototype._lex):
  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.html:
Location:
trunk/WebCore
Files:
2 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r52974 r52985  
     12010-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
    1272010-01-07  Mike Belshe  <mbelshe@chromium.org>
    228
  • trunk/WebCore/WebCore.gypi

    r52949 r52985  
    36963696            'inspector/front-end/InjectedScriptAccess.js',
    36973697            'inspector/front-end/inspector.js',
    3698             'inspector/front-end/JavaScriptHighlighterScheme.js',
    36993698            'inspector/front-end/JavaScriptSourceSyntaxHighlighter.js',
     3699            'inspector/front-end/JavaScriptTokenizer.js',
    37003700            'inspector/front-end/KeyboardShortcut.js',
    37013701            'inspector/front-end/MetricsSidebarPane.js',
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r52949 r52985  
    4286542865                                </File>
    4286642866                                <File
    42867                                         RelativePath="..\inspector\front-end\JavaScriptHighlighterScheme.js"
    42868                                         >
    42869                                 </File>
    42870                                 <File
    4287142867                                        RelativePath="..\inspector\front-end\JavaScriptSourceSyntaxHighlighter.js"
     42868                                        >
     42869                                </File>
     42870                                <File
     42871                                        RelativePath="..\inspector\front-end\JavaScriptTokenizer.js"
    4287242872                                        >
    4287342873                                </File>
  • trunk/WebCore/inspector/front-end/TextEditorHighlighter.js

    r52945 r52985  
    3333{
    3434    this._textModel = textModel;
    35     this._highlighterScheme = new WebInspector.JavaScriptHighlighterScheme();
     35    this._tokenizer = new WebInspector.JavaScriptTokenizer();
    3636
    3737    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)";
    4943}
    5044
     
    5246    highlight: function(startLine, endLine)
    5347    {
    54         this._highlighterScheme.reset(this);
    5548        // Rewind to the last highlighted line to gain proper highlighter context.
    5649        while (startLine > 0 && !this._textModel.getAttribute(startLine - 1, 0, "highlighter-state"))
     
    5952        // Restore highlighter context taken from previous line.
    6053        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;
    6658        // Each line has associated state attribute with pre- and post-highlighter conditions.
    6759        // Highlight lines from range until we find line precondition matching highlighter state.
     
    6961        for (var i = startLine; i < endLine; ++i) {
    7062            state = this._textModel.getAttribute(i, 0, "highlighter-state");
    71             if (state && state.preContinueState === this.continueState && state.preLexState === this.lexState) {
     63            if (state && state.preCondition === this._tokenizer.condition) {
    7264                // 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;
    7566                continue;
    7667            }
     
    7970
    8071            state = {};
    81             state.preContinueState = this.continueState;
    82             state.preLexState = this.lexState;
     72            state.preCondition = this._tokenizer.condition;
    8373
    8474            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);
    8876
    89             state.postContinueState = this.continueState;
    90             state.postLexState = this.lexState;
     77            state.postCondition = this._tokenizer.condition;
    9178            this._textModel.addAttribute(i, 0, "highlighter-state", state);
    9279        }
     
    9481        state = this._textModel.getAttribute(endLine, 0, "highlighter-state");
    9582
    96         if (state && (state.preContinueState !== this.continueState || state.preLexState !== this.lexState)) {
     83        if (state && state.preCondition !== this._tokenizer.condition) {
    9784            // Requested highlight range is over, but we did not recover. Invalidate tail highlighting.
    9885            for (var i = endLine; i < this._textModel.linesCount; ++i)
    9986                this._textModel.removeAttributes(i, "highlighter-state");
    10087        }
    101 
    10288        return damage;
    10389    },
    10490
    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)
    130101    }
    131102}
  • trunk/WebCore/inspector/front-end/WebKit.qrc

    r52945 r52985  
    3636    <file>InspectorBackendStub.js</file>
    3737    <file>InspectorFrontendHostStub.js</file>
    38     <file>JavaScriptHighlighterScheme.js</file>
    3938    <file>JavaScriptSourceSyntaxHighlighter.js</file>
     39    <file>JavaScriptTokenizer.js</file>
    4040    <file>KeyboardShortcut.js</file>
    4141    <file>MetricsSidebarPane.js</file>
  • trunk/WebCore/inspector/front-end/inspector.html

    r52945 r52985  
    9898    <script type="text/javascript" src="TextEditor.js"></script>
    9999    <script type="text/javascript" src="TextEditorHighlighter.js"></script>
    100     <script type="text/javascript" src="JavaScriptHighlighterScheme.js"></script>
     100    <script type="text/javascript" src="JavaScriptTokenizer.js"></script>
    101101    <script type="text/javascript" src="SourceView.js"></script>
    102102    <script type="text/javascript" src="FontView.js"></script>
Note: See TracChangeset for help on using the changeset viewer.