Changeset 50755 in webkit


Ignore:
Timestamp:
Nov 10, 2009 1:04:04 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-10 Keishi Hattori <casey.hattori@gmail.com>

Reviewed by Timothy Hatcher.

Web Inspector: Speed up syntax highlighter
https://bugs.webkit.org/show_bug.cgi?id=31291

  • inspector/front-end/SourceFrame.js: (WebInspector.SourceFrame.prototype._loaded): (WebInspector.SourceSyntaxHighlighter.prototype.process.moveToNextLine): Replace the line content node. (WebInspector.SourceSyntaxHighlighter.prototype.process): (WebInspector.SourceSyntaxHighlighter.prototype.appendNonToken): (WebInspector.SourceSyntaxHighlighter.prototype.syntaxHighlightNode): (WebInspector.CSSSourceSyntaxHighlighter): (WebInspector.JavaScriptSourceSyntaxHighlighter):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r50754 r50755  
     12009-11-10  Keishi Hattori  <casey.hattori@gmail.com>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: Speed up syntax highlighter
     6        https://bugs.webkit.org/show_bug.cgi?id=31291
     7
     8        * inspector/front-end/SourceFrame.js:
     9        (WebInspector.SourceFrame.prototype._loaded):
     10        (WebInspector.SourceSyntaxHighlighter.prototype.process.moveToNextLine): Replace the line content node.
     11        (WebInspector.SourceSyntaxHighlighter.prototype.process):
     12        (WebInspector.SourceSyntaxHighlighter.prototype.appendNonToken):
     13        (WebInspector.SourceSyntaxHighlighter.prototype.syntaxHighlightNode):
     14        (WebInspector.CSSSourceSyntaxHighlighter):
     15        (WebInspector.JavaScriptSourceSyntaxHighlighter):
     16
    1172009-11-09  Jeremy Orlow  <jorlow@chromium.org>
    218
  • trunk/WebCore/inspector/front-end/SourceFrame.js

    r50664 r50755  
    265265        this.element.contentWindow.Element.prototype.addStyleClass = Element.prototype.addStyleClass;
    266266        this.element.contentWindow.Element.prototype.removeStyleClass = Element.prototype.removeStyleClass;
     267        this.element.contentWindow.Element.prototype.removeChildren = Element.prototype.removeChildren;
    267268        this.element.contentWindow.Element.prototype.positionAt = Element.prototype.positionAt;
    268269        this.element.contentWindow.Element.prototype.removeMatchingStyleClasses = Element.prototype.removeMatchingStyleClasses;
     
    793794            var row = rows[this.lineIndex];
    794795            var line = row ? row.cells[1] : null;
    795             if (line && this.lineFragment) {
    796                 Element.prototype.removeChildren.call(line);
     796            if (line && this.newLine) {
     797                line.removeChildren();
    797798               
    798                 line.appendChild(this.lineFragment);
    799799                if (this.messageBubble)
    800                     line.appendChild(this.messageBubble);
    801                 this.lineFragment = null;
     800                    this.newLine.appendChild(this.messageBubble);
     801               
     802                line.parentNode.insertBefore(this.newLine, line);
     803                line.parentNode.removeChild(line);
     804               
     805                this.newLine = null;
    802806            }
    803807            this.lineIndex++;
     
    817821
    818822            this.lineCode = line.textContent;
    819             this.lineFragment = document.createDocumentFragment();
     823            this.newLine = line.cloneNode(false);
    820824            this.cursor = 0;
    821825            if (!line)
     
    853857    {
    854858        if (this.nonToken.length > 0) {
    855             this.lineFragment.appendChild(document.createTextNode(this.nonToken));
     859            this.newLine.appendChild(document.createTextNode(this.nonToken));
    856860            this.nonToken = "";
    857861        }
     
    861865    {
    862866        this.lineCode = node.textContent;
    863         this.lineFragment = document.createDocumentFragment();
     867        node.removeChildren();
     868        this.newLine = node;
    864869        this.cursor = 0;
    865870        while (true) {
     
    869874                this.cursor += codeFragment.length;
    870875                this.appendNonToken();
    871                 while (node.firstChild)
    872                     node.removeChild(node.firstChild);
    873                 node.appendChild(this.lineFragment);
    874                 this.lineFragment =null;
     876                this.newLine = null;
    875877                return;
    876878            }
     
    901903    this.lineIndex = -1;
    902904    this.lineCode = "";
    903     this.lineFragment = null;
     905    this.newLine = null;
    904906    this.lexState = this.LexState.Initial;
    905907    this.continueState = this.ContinueState.None;
     
    10411043    {
    10421044        this.cursor += token.length;
    1043         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-comment"));
     1045        this.newLine.appendChild(this.createSpan(token, "webkit-css-comment"));
    10441046    }
    10451047   
     
    10471049    {
    10481050        this.cursor += token.length;
    1049         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-comment"));
     1051        this.newLine.appendChild(this.createSpan(token, "webkit-css-comment"));
    10501052        this.continueState = this.ContinueState.Comment;
    10511053    }
     
    10541056    {
    10551057        this.cursor += token.length;
    1056         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-comment"));
     1058        this.newLine.appendChild(this.createSpan(token, "webkit-css-comment"));
    10571059        this.continueState = this.ContinueState.None;
    10581060    }
     
    10611063    {
    10621064        this.cursor += token.length;
    1063         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-comment"));
     1065        this.newLine.appendChild(this.createSpan(token, "webkit-css-comment"));
    10641066    }
    10651067   
     
    10671069    {
    10681070        this.cursor += token.length;
    1069         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-selector"));
     1071        this.newLine.appendChild(this.createSpan(token, "webkit-css-selector"));
    10701072    }
    10711073   
     
    13311333        if (token in propertyKeywords) {
    13321334            this.appendNonToken.call(this);
    1333             this.lineFragment.appendChild(this.createSpan(token, "webkit-css-property"));
     1335            this.newLine.appendChild(this.createSpan(token, "webkit-css-property"));
    13341336        } else
    13351337            this.nonToken += token;
     
    17311733        if (token in valueKeywords) {
    17321734            this.appendNonToken.call(this);
    1733             this.lineFragment.appendChild(this.createSpan(token, "webkit-css-keyword"));
     1735            this.newLine.appendChild(this.createSpan(token, "webkit-css-keyword"));
    17341736        } else
    17351737            this.nonToken += token;
     
    17391741    {
    17401742        this.cursor += token.length;
    1741         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-number"));
     1743        this.newLine.appendChild(this.createSpan(token, "webkit-css-number"));
    17421744    }
    17431745   
     
    17521754    {
    17531755        this.cursor += token.length;
    1754         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-url"));
     1756        this.newLine.appendChild(this.createSpan(token, "webkit-css-url"));
    17551757    }
    17561758   
     
    17581760    {
    17591761        this.cursor += token.length;
    1760         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-string"));
     1762        this.newLine.appendChild(this.createSpan(token, "webkit-css-string"));
    17611763    }
    17621764   
     
    17641766    {
    17651767        this.cursor += token.length;
    1766         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-color"));
     1768        this.newLine.appendChild(this.createSpan(token, "webkit-css-color"));
    17671769    }
    17681770   
     
    17701772    {
    17711773        this.cursor += token.length;
    1772         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-important"));
     1774        this.newLine.appendChild(this.createSpan(token, "webkit-css-important"));
    17731775    }
    17741776   
     
    17761778    {
    17771779        this.cursor += token.length;
    1778         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-at-rule"));
     1780        this.newLine.appendChild(this.createSpan(token, "webkit-css-at-rule"));
    17791781        this.lexState = this.LexState.AtMedia;
    17801782    }
     
    17901792    {
    17911793        this.cursor += token.length;
    1792         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-at-rule"));
     1794        this.newLine.appendChild(this.createSpan(token, "webkit-css-at-rule"));
    17931795        this.lexState = this.LexState.AtKeyframes;
    17941796    }
     
    18031805    function atRuleAction(token) {
    18041806        this.cursor += token.length;
    1805         this.lineFragment.appendChild(this.createSpan(token, "webkit-css-at-rule"));
     1807        this.newLine.appendChild(this.createSpan(token, "webkit-css-at-rule"));
    18061808        this.lexState = this.LexState.AtRule;
    18071809    }
     
    18271829        else {
    18281830            this.appendNonToken.call(this);
    1829             this.lineFragment.appendChild(this.createSpan(token, "webkit-css-keyword"));
     1831            this.newLine.appendChild(this.createSpan(token, "webkit-css-keyword"));
    18301832        }
    18311833    }
     
    18531855    this.lineIndex = -1;
    18541856    this.lineCode = "";
    1855     this.lineFragment = null;
     1857    this.newLine = null;
    18561858    this.lexState = this.LexState.Initial;
    18571859    this.continueState = this.ContinueState.None;
     
    19041906    }, {
    19051907        pattern: /^(?:(?:[a-zA-Z]|[$_]|\\(?:u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]))(?:(?:[a-zA-Z]|[$_]|\\(?:u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]))|[0-9])*)/,
    1906         action: identOrKeywordAction,
    1907         dontAppendNonToken: true
     1908        action: identOrKeywordAction
    19081909    }, {
    19091910        pattern: /^\)/,
     
    19381939    {
    19391940        this.cursor += token.length;
    1940         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-comment"));
     1941        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-comment"));
    19411942    }
    19421943   
     
    19441945    {
    19451946        this.cursor += token.length;
    1946         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-comment"));
     1947        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-comment"));
    19471948    }
    19481949   
     
    19501951    {
    19511952        this.cursor += token.length;
    1952         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-comment"));
     1953        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-comment"));
    19531954        this.continueState = this.ContinueState.Comment;
    19541955    }
     
    19571958    {
    19581959        this.cursor += token.length;
    1959         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-comment"));
     1960        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-comment"));
    19601961        this.continueState = this.ContinueState.None;
    19611962    }
     
    19641965    {
    19651966        this.cursor += token.length;
    1966         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-comment"));
     1967        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-comment"));
    19671968    }
    19681969   
     
    19701971    {
    19711972        this.cursor += token.length;
    1972         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-number"));
     1973        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-number"));
    19731974        this.lexState = this.LexState.DivisionAllowed;
    19741975    }
     
    19771978    {
    19781979        this.cursor += token.length;
    1979         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     1980        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    19801981        this.lexState = this.LexState.Initial;
    19811982    }
     
    19841985    {
    19851986        this.cursor += token.length;
    1986         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     1987        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    19871988        this.continueState = this.ContinueState.SingleQuoteString;
    19881989    }
     
    19911992    {
    19921993        this.cursor += token.length;
    1993         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     1994        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    19941995        this.continueState = this.ContinueState.None;
    19951996    }
     
    19981999    {
    19992000        this.cursor += token.length;
    2000         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     2001        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    20012002    }
    20022003   
     
    20042005    {
    20052006        this.cursor += token.length;
    2006         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     2007        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    20072008        this.continueState = this.ContinueState.DoubleQuoteString;
    20082009    }
     
    20112012    {
    20122013        this.cursor += token.length;
    2013         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     2014        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    20142015        this.continueState = this.ContinueState.None;
    20152016    }
     
    20182019    {
    20192020        this.cursor += token.length;
    2020         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-string"));
     2021        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-string"));
    20212022    }
    20222023   
     
    20242025    {
    20252026        this.cursor += token.length;
    2026         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
     2027        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
    20272028        this.lexState = this.LexState.Initial;
    20282029    }
     
    20312032    {
    20322033        this.cursor += token.length;
    2033         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
     2034        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
    20342035        this.continueState = this.ContinueState.RegExp;
    20352036    }
     
    20382039    {
    20392040        this.cursor += token.length;
    2040         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
     2041        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
    20412042        this.continueState = this.ContinueState.None;
    20422043    }
     
    20452046    {
    20462047        this.cursor += token.length;
    2047         this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
    2048     }
    2049    
     2048        this.newLine.appendChild(this.createSpan(token, "webkit-javascript-regexp"));
     2049    }
     2050   
     2051    const keywords = {
     2052        "null": true,
     2053        "true": true,
     2054        "false": true,
     2055        "break": true,
     2056        "case": true,
     2057        "catch": true,
     2058        "const": true,
     2059        "default": true,
     2060        "finally": true,
     2061        "for": true,
     2062        "instanceof": true,
     2063        "new": true,
     2064        "var": true,
     2065        "continue": true,
     2066        "function": true,
     2067        "return": true,
     2068        "void": true,
     2069        "delete": true,
     2070        "if": true,
     2071        "this": true,
     2072        "do": true,
     2073        "while": true,
     2074        "else": true,
     2075        "in": true,
     2076        "switch": true,
     2077        "throw": true,
     2078        "try": true,
     2079        "typeof": true,
     2080        "debugger": true,
     2081        "class": true,
     2082        "enum": true,
     2083        "export": true,
     2084        "extends": true,
     2085        "import": true,
     2086        "super": true,
     2087        "get": true,
     2088        "set": true
     2089    };
    20502090    function identOrKeywordAction(token)
    20512091    {
    2052         const keywords = ["null", "true", "false", "break", "case", "catch", "const", "default", "finally", "for", "instanceof", "new", "var", "continue", "function", "return", "void", "delete", "if", "this", "do", "while", "else", "in", "switch", "throw", "try", "typeof", "with", "debugger", "class", "enum", "export", "extends", "import", "super", "get", "set"];
    2053         this.cursor += token.length;
    2054         if (keywords.indexOf(token) === -1) {
    2055             this.appendNonToken();
     2092        this.cursor += token.length;
     2093       
     2094        if (token in keywords) {
     2095            this.newLine.appendChild(this.createSpan(token, "webkit-javascript-keyword"));
     2096            this.lexState = this.LexState.Initial;
     2097        } else {
    20562098            var identElement = this.createSpan(token, "webkit-javascript-ident");
    20572099            identElement.addEventListener("mouseover", showDatatip, false);
    2058             this.lineFragment.appendChild(identElement);
     2100            this.newLine.appendChild(identElement);
    20592101            this.lexState = this.LexState.DivisionAllowed;
    2060         } else {
    2061             this.appendNonToken();
    2062             this.lineFragment.appendChild(this.createSpan(token, "webkit-javascript-keyword"));
    2063             this.lexState = this.LexState.Initial;
    20642102        }
    20652103    }
Note: See TracChangeset for help on using the changeset viewer.