mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02: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
14
lib/md045.js
14
lib/md045.js
|
@ -4,6 +4,7 @@
|
|||
|
||||
const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers");
|
||||
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
const altRe = getHtmlAttributeRe("alt");
|
||||
|
||||
|
@ -15,13 +16,8 @@ module.exports = {
|
|||
"tags": [ "accessibility", "images" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD045(params, onError) {
|
||||
const micromarkTokens = params.parsers.micromark.tokens;
|
||||
|
||||
// Process Markdown images
|
||||
const images = filterByTypes(
|
||||
micromarkTokens,
|
||||
[ "image" ]
|
||||
);
|
||||
const images = filterByTypesCached([ "image" ]);
|
||||
for (const image of images) {
|
||||
const labelTexts = filterByTypes(image.children, [ "labelText" ]);
|
||||
if (labelTexts.some((labelText) => labelText.text.length === 0)) {
|
||||
|
@ -39,11 +35,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Process HTML images
|
||||
const htmlTexts = filterByTypes(
|
||||
micromarkTokens,
|
||||
[ "htmlText" ],
|
||||
true
|
||||
);
|
||||
const htmlTexts = filterByTypesCached([ "htmlText" ], true);
|
||||
for (const htmlText of htmlTexts) {
|
||||
const { startColumn, startLine, text } = htmlText;
|
||||
const htmlTagInfo = getHtmlTagInfo(htmlText);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue