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 { addErrorDetailIf } = require("../helpers");
const { addRangeToSet, filterByTypes } = require("../helpers/micromark.cjs");
const { addRangeToSet } = require("../helpers/micromark.cjs");
const { filterByTypesCached } = require("./cache");
// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
@ -14,9 +15,9 @@ module.exports = {
"parser": "micromark",
"function": function MD012(params, onError) {
const maximum = Number(params.config.maximum || 1);
const { lines, parsers } = params;
const { lines } = params;
const codeBlockLineNumbers = new Set();
for (const codeBlock of filterByTypes(parsers.micromark.tokens, [ "codeFenced", "codeIndented" ])) {
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
addRangeToSet(codeBlockLineNumbers, codeBlock.startLine, codeBlock.endLine);
}
let count = 0;