mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-27 03:12:44 +03:00
Removed CancelToken and its use in parser. It's not used, so it's just overhead.
This commit is contained in:
parent
4513e4b795
commit
bb68ebb921
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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()) {
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user