mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Cache all top-level calls to filterByTypes (~7% runtime reduction).
This commit is contained in:
parent
85e704f32a
commit
dfcb4529f3
47 changed files with 427 additions and 481 deletions
11
lib/md042.js
11
lib/md042.js
|
|
@ -3,8 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext } = require("../helpers");
|
||||
const { getDescendantsByType, filterByTypes } = require("../helpers/micromark.cjs");
|
||||
const { referenceLinkImageData } = require("./cache");
|
||||
const { getDescendantsByType } = require("../helpers/micromark.cjs");
|
||||
const { getReferenceLinkImageData, filterByTypesCached } = require("./cache");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
|
|
@ -14,15 +14,12 @@ module.exports = {
|
|||
"tags": [ "links" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD042(params, onError) {
|
||||
const { definitions } = referenceLinkImageData();
|
||||
const { definitions } = getReferenceLinkImageData();
|
||||
const isReferenceDefinitionHash = (token) => {
|
||||
const definition = definitions.get(token.text.trim());
|
||||
return (definition && (definition[1] === "#"));
|
||||
};
|
||||
const links = filterByTypes(
|
||||
params.parsers.micromark.tokens,
|
||||
[ "link" ]
|
||||
);
|
||||
const links = filterByTypesCached([ "link" ]);
|
||||
for (const link of links) {
|
||||
const labelText = getDescendantsByType(link, [ "label", "labelText" ]);
|
||||
const reference = getDescendantsByType(link, [ "reference" ]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue