This commit is contained in:
Alex Dima 2020-04-28 00:47:21 +02:00
Родитель 025892d959
Коммит 1b66ea9184
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6E58D7B045760DA0
2 изменённых файлов: 30 добавлений и 10 удалений

Просмотреть файл

@ -2272,6 +2272,15 @@ var utils_1 = require("./utils");
var rule_1 = require("./rule");
var matcher_1 = require("./matcher");
var debug_1 = require("./debug");
var performanceNow = (function () {
if (typeof performance === 'undefined') {
// performance.now() is not available in this environment, so use Date.now()
return function () { return Date.now(); };
}
else {
return function () { return performance.now(); };
}
})();
function createGrammar(grammar, initialLanguage, embeddedLanguages, tokenTypes, grammarRepository, onigLib) {
return new Grammar(grammar, initialLanguage, embeddedLanguages, tokenTypes, grammarRepository, onigLib); //TODO
}
@ -2829,8 +2838,16 @@ function matchInjections(injections, grammar, lineText, isFirstLine, linePos, st
function matchRule(grammar, lineText, isFirstLine, linePos, stack, anchorPosition) {
var rule = stack.getRule(grammar);
var ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos === anchorPosition);
var perfStart = 0;
if (debug_1.DebugFlags.InDebugMode) {
perfStart = performanceNow();
}
var r = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
if (debug_1.DebugFlags.InDebugMode) {
var elapsedMillis = performanceNow() - perfStart;
if (elapsedMillis > 5) {
console.warn("Rule " + rule.debugName + " (" + rule.id + ") matching took " + elapsedMillis + " against '" + lineText + "'");
}
// console.log(` scanning for (linePos: ${linePos}, anchorPosition: ${anchorPosition})`);
// console.log(debugCompiledRuleToString(ruleScanner));
if (r) {

Просмотреть файл

@ -11,9 +11,14 @@ import { DebugFlags } from './debug';
import { FontStyle, ThemeTrieElementRule } from './theme';
declare let performance: { now: () => number } | undefined;
if (typeof process !== 'undefined' && process.release.name === 'node') {
performance = require('perf_hooks').performance;
}
const performanceNow = (function() {
if (typeof performance === 'undefined') {
// performance.now() is not available in this environment, so use Date.now()
return () => Date.now();
} else {
return () => performance!.now();
}
})();
export const enum TemporaryStandardTokenType {
Other = 0,
@ -710,18 +715,16 @@ function matchRule(grammar: Grammar, lineText: OnigString, isFirstLine: boolean,
const ruleScanner = rule.compile(grammar, stack.endRule, isFirstLine, linePos === anchorPosition);
let perfStart = 0;
if (DebugFlags.InDebugMode && performance) {
perfStart = performance.now();
if (DebugFlags.InDebugMode) {
perfStart = performanceNow();
}
const r = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
if (DebugFlags.InDebugMode) {
if (performance) {
const timeMillis = performance.now() - perfStart;
if (timeMillis > 5) {
console.warn(`Rule ${rule.debugName} (${rule.id}) matching took ${timeMillis} against '${lineText}'`);
}
const elapsedMillis = performanceNow() - perfStart;
if (elapsedMillis > 5) {
console.warn(`Rule ${rule.debugName} (${rule.id}) matching took ${elapsedMillis} against '${lineText}'`);
}
// console.log(` scanning for (linePos: ${linePos}, anchorPosition: ${anchorPosition})`);
// console.log(debugCompiledRuleToString(ruleScanner));