Removed CancelToken and its use in parser. It's not used, so it's just overhead.

This commit is contained in:
Eric Traut 2019-11-17 20:51:04 -08:00
parent 4513e4b795
commit bb68ebb921
4 changed files with 5 additions and 53 deletions

View File

@ -1,30 +0,0 @@
/*
* cancelToken.ts
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
* Author: Eric Traut
*
* A simple class that allows a caller to cancel an async operation.
* The async operation needs to cooperatively check for cancellation.
*/
export class CancelError extends Error {
}
export class CancelToken {
private _isCanceled = false;
cancel(): void {
this._isCanceled = true;
}
isCanceled(): boolean {
return this._isCanceled;
}
throwIfCanceled(): void {
if (this._isCanceled) {
throw new CancelError();
}
}
}

View File

@ -17,10 +17,6 @@ export class Duration {
this._startTime = Date.now();
}
restart() {
this._startTime = Date.now();
}
getDurationInMilliseconds() {
const curTime = Date.now();
return curTime - this._startTime;

View File

@ -13,7 +13,6 @@
import * as assert from 'assert';
import { CancelToken } from '../common/cancelToken';
import { Diagnostic } from '../common/diagnostic';
import { DiagnosticSink } from '../common/diagnosticSink';
import { convertOffsetsToRange, convertPositionToOffset } from '../common/positionUtils';
@ -86,7 +85,6 @@ export class Parser {
private _tokenizerOutput?: TokenizerOutput;
private _tokenIndex = 0;
private _parseOptions: ParseOptions = new ParseOptions();
private _cancelToken?: CancelToken;
private _diagSink: DiagnosticSink = new DiagnosticSink();
private _isInLoop = false;
private _isInFinally = false;
@ -96,11 +94,11 @@ export class Parser {
private _containsWildcardImport = false;
parseSourceFile(fileContents: string, parseOptions: ParseOptions,
diagSink: DiagnosticSink, cancelToken?: CancelToken): ParseResults {
diagSink: DiagnosticSink): ParseResults {
timingStats.tokenizeFileTime.timeOperation(() => {
this._startNewParse(fileContents, 0, fileContents.length,
parseOptions, diagSink, cancelToken);
parseOptions, diagSink);
});
const moduleNode = ModuleNode.create({ start: 0, length: fileContents.length });
@ -124,8 +122,6 @@ export class Parser {
statement.parent = moduleNode;
moduleNode.statements.push(statement);
}
this._checkCancel();
}
}
});
@ -164,20 +160,15 @@ export class Parser {
}
private _startNewParse(fileContents: string, textOffset: number, textLength: number,
parseOptions: ParseOptions, diagSink: DiagnosticSink, cancelToken?: CancelToken) {
parseOptions: ParseOptions, diagSink: DiagnosticSink) {
this._fileContents = fileContents;
this._parseOptions = parseOptions;
this._cancelToken = cancelToken;
this._diagSink = diagSink;
this._checkCancel();
// Tokenize the file contents.
const tokenizer = new Tokenizer();
this._tokenizerOutput = tokenizer.tokenize(fileContents, textOffset, textLength);
this._tokenIndex = 0;
this._checkCancel();
}
// stmt: simple_stmt | compound_stmt
@ -2837,12 +2828,6 @@ export class Parser {
return false;
}
private _checkCancel() {
if (this._cancelToken) {
this._cancelToken.throwIfCanceled();
}
}
private _getNextToken(): Token {
const token = this._tokenizerOutput!.tokens.getItemAt(this._tokenIndex);
if (!this._atEof()) {

View File

@ -4,7 +4,8 @@
* Licensed under the MIT license.
* Author: Eric Traut
*
* Unit tests for Python parser.
* Unit tests for Python parser. These are very basic because
* the parser gets lots of exercise in the type checker tests.
*/
import * as assert from 'assert';