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,7 @@
"use strict";
const { addErrorDetailIf } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
const { filterByTypesCached } = require("./cache");
const tokenTypeToStyle = {
"codeFenced": "fenced",
@ -19,11 +19,7 @@ module.exports = {
"parser": "micromark",
"function": function MD046(params, onError) {
let expectedStyle = String(params.config.style || "consistent");
const codeBlocksAndFences = filterByTypes(
params.parsers.micromark.tokens,
[ "codeFenced", "codeIndented" ]
);
for (const token of codeBlocksAndFences) {
for (const token of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
const { startLine, type } = token;
if (expectedStyle === "consistent") {
expectedStyle = tokenTypeToStyle[type];