提交 90deb54f 编写于 作者: A Alex Dima

Remove usage of performance.now in TextModelWithTokens (#1439)

上级 5f5963da
......@@ -10,27 +10,32 @@ var hasPerformanceNow = (globals.performance && typeof globals.performance.now =
export class StopWatch {
private _highResolution: boolean;
private _startTime: number;
private _stopTime: number;
public static create(): StopWatch {
return new StopWatch(hasPerformanceNow ? globals.performance.now() : new Date().getTime());
public static create(highResolution:boolean = true): StopWatch {
return new StopWatch(highResolution);
}
constructor(startTime: number) {
this._startTime = startTime;
constructor(highResolution: boolean) {
this._highResolution = hasPerformanceNow && highResolution;
this._startTime = this._now();
this._stopTime = -1;
}
public stop(): void {
this._stopTime = (hasPerformanceNow ? globals.performance.now() : new Date().getTime());
this._stopTime = this._now();
}
public elapsed(): number {
if (this._stopTime !== -1) {
return this._stopTime - this._startTime;
}
var now = (hasPerformanceNow ? globals.performance.now() : new Date().getTime());
return now - this._startTime;
return this._now() - this._startTime;
}
private _now(): number {
return this._highResolution ? globals.performance.now() : new Date().getTime();
}
}
......@@ -600,7 +600,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
currentCharsToTokenize = 0,
currentEstimatedTimeToTokenize = 0,
stopLineTokenizationAfter = this._stopLineTokenizationAfter,
sw = StopWatch.create(),
sw = StopWatch.create(false),
elapsedTime: number;
// Tokenize at most 1000 lines. Estimate the tokenization speed per character and stop when:
......@@ -682,7 +682,7 @@ export class TextModelWithTokens extends TextModel implements editorCommon.IToke
stopLineTokenizationAfter = 1000000000; // 1 billion, if a line is so long, you have other trouble :).
}
var sw = StopWatch.create();
var sw = StopWatch.create(false);
var tokenizedCharacters = 0;
var fromLineNumber = this._invalidLineStartIndex + 1, toLineNumber = lineNumber;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册