Small micro optimizations to incremental parsing.

This commit is contained in:
Cyrus Najmabadi
2014-11-04 01:19:19 -08:00
parent 7c0c788886
commit aa2509a08a
3 changed files with 15 additions and 18 deletions
+9 -5
View File
@@ -711,12 +711,16 @@ module TypeScript.Parser {
return sourceUnit;
}
function isDirectivePrologueElement(node: ISyntaxNodeOrToken): boolean {
return node.kind === SyntaxKind.ExpressionStatement &&
(<ExpressionStatementSyntax>node).expression.kind === SyntaxKind.StringLiteral;
}
function updateStrictModeState(items: any[]): void {
if (!isInStrictMode) {
// Check if all the items are directive prologue elements.
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (!SyntaxFacts.isDirectivePrologueElement(item)) {
for (var i = 0, n = items.length; i < n; i++) {
if (!isDirectivePrologueElement(items[i])) {
return;
}
}
@@ -3864,7 +3868,7 @@ module TypeScript.Parser {
}
function tryParseExpectedListItem(
currentListType: ListParsingState, inErrorRecovery: boolean, items: ISyntaxElement[], processItems: (items: any[]) => void): boolean {
currentListType: ListParsingState, inErrorRecovery: boolean, items: ISyntaxNodeOrToken[], processItems: (items: ISyntaxNodeOrToken[]) => void): boolean {
var item = tryParseExpectedListItemWorker(currentListType, inErrorRecovery);
if (item === undefined) {
@@ -3886,7 +3890,7 @@ module TypeScript.Parser {
currentToken().kind === SyntaxKind.EndOfFileToken;
}
function parseSyntaxListWorker<T extends ISyntaxNodeOrToken>(currentListType: ListParsingState, skippedTokens: ISyntaxToken[], processItems: (items: any[]) => void ): T[] {
function parseSyntaxListWorker<T extends ISyntaxNodeOrToken>(currentListType: ListParsingState, skippedTokens: ISyntaxToken[], processItems: (items: ISyntaxNodeOrToken[]) => void ): T[] {
var items: T[] = [];
while (true) {
+4 -3
View File
@@ -349,12 +349,13 @@ module TypeScript.Scanner {
}
function reset(_text: ISimpleText, _start: number, _end: number) {
Debug.assert(_start <= _text.length(), "Token's start was not within the bounds of text: " + _start + " - [0, " + _text.length() + ")");
Debug.assert(_end <= _text.length(), "Token's end was not within the bounds of text: " + _end + " - [0, " + _text.length() + ")");
var textLength = _text.length();
Debug.assert(_start <= textLength, "Token's start was not within the bounds of text.");
Debug.assert(_end <= textLength, "Token's end was not within the bounds of text:");
if (!str || text !== _text) {
text = _text;
str = _text.substr(0, _text.length());
str = _text.substr(0, textLength);
}
start = _start;
+2 -10
View File
@@ -2,16 +2,8 @@
module TypeScript.SyntaxFacts {
export function isDirectivePrologueElement(node: ISyntaxNodeOrToken): boolean {
if (node.kind === SyntaxKind.ExpressionStatement) {
var expressionStatement = <ExpressionStatementSyntax>node;
var expression = expressionStatement.expression;
if (expression.kind === SyntaxKind.StringLiteral) {
return true;
}
}
return false;
return node.kind === SyntaxKind.ExpressionStatement &&
(<ExpressionStatementSyntax>node).expression.kind === SyntaxKind.StringLiteral;
}
export function isUseStrictDirective(node: ISyntaxNodeOrToken): boolean {