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

@ -4,6 +4,7 @@
const { addErrorContext } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
const { filterByTypesCached } = require("./cache");
const dollarCommandRe = /^(\s*)(\$\s+)/;
@ -15,11 +16,7 @@ module.exports = {
"tags": [ "code" ],
"parser": "micromark",
"function": function MD014(params, onError) {
const codeBlocks = filterByTypes(
params.parsers.micromark.tokens,
[ "codeFenced", "codeIndented" ]
);
for (const codeBlock of codeBlocks) {
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
const codeFlowValues = filterByTypes(
codeBlock.children,
[ "codeFlowValue" ]