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,7 +4,7 @@
const { addErrorContext } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
const { referenceLinkImageData } = require("./cache");
const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
/**
* Adds an error for a label space issue.
@ -56,11 +56,9 @@ module.exports = {
"tags": [ "whitespace", "links" ],
"parser": "micromark",
"function": function MD039(params, onError) {
const { definitions } = referenceLinkImageData();
const labels = filterByTypes(
params.parsers.micromark.tokens,
[ "label" ]
).filter((label) => label.parent?.type === "link");
const { definitions } = getReferenceLinkImageData();
const labels = filterByTypesCached([ "label" ]).
filter((label) => label.parent?.type === "link");
for (const label of labels) {
const labelTexts = filterByTypes(
label.children,