Cache all top-level calls to filterByTypes (~7% runtime reduction).

This commit is contained in:
David Anson 2024-08-24 22:05:16 -07:00
parent 85e704f32a
commit dfcb4529f3
47 changed files with 427 additions and 481 deletions

View file

@ -3,7 +3,8 @@
"use strict";
const { addError, withinAnyRange } = require("../helpers");
const { addRangeToSet, getExclusionsForToken, filterByTypes } = require("../helpers/micromark.cjs");
const { addRangeToSet, getExclusionsForToken } = require("../helpers/micromark.cjs");
const { filterByTypesCached } = require("./cache");
const reversedLinkRe =
/(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g;
@ -16,13 +17,12 @@ module.exports = {
"tags": [ "links" ],
"parser": "micromark",
"function": function MD011(params, onError) {
const { tokens } = params.parsers.micromark;
const codeBlockLineNumbers = new Set();
for (const codeBlock of filterByTypes(tokens, [ "codeFenced", "codeIndented" ])) {
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
}
const exclusions = [];
for (const codeText of filterByTypes(tokens, [ "codeText" ])) {
for (const codeText of filterByTypesCached([ "codeText" ])) {
exclusions.push(...getExclusionsForToken(params.lines, codeText));
}
for (const [ lineIndex, line ] of params.lines.entries()) {