mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +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
|
|
@ -3,7 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext } = require("../helpers/helpers");
|
||||
const { filterByTypes, getHeadingStyle } = require("../helpers/micromark.cjs");
|
||||
const { getHeadingStyle } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
/**
|
||||
* Validate heading sequence and whitespace length at start or end.
|
||||
|
|
@ -55,10 +56,8 @@ module.exports = [
|
|||
"tags": [ "headings", "atx", "spaces" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD019(params, onError) {
|
||||
const atxHeadings = filterByTypes(
|
||||
params.parsers.micromark.tokens,
|
||||
[ "atxHeading" ]
|
||||
).filter((heading) => getHeadingStyle(heading) === "atx");
|
||||
const atxHeadings = filterByTypesCached([ "atxHeading" ])
|
||||
.filter((heading) => getHeadingStyle(heading) === "atx");
|
||||
for (const atxHeading of atxHeadings) {
|
||||
validateHeadingSpaces(onError, atxHeading, 1);
|
||||
}
|
||||
|
|
@ -70,10 +69,8 @@ module.exports = [
|
|||
"tags": [ "headings", "atx_closed", "spaces" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD021(params, onError) {
|
||||
const atxClosedHeadings = filterByTypes(
|
||||
params.parsers.micromark.tokens,
|
||||
[ "atxHeading" ]
|
||||
).filter((heading) => getHeadingStyle(heading) === "atx_closed");
|
||||
const atxClosedHeadings = filterByTypesCached([ "atxHeading" ])
|
||||
.filter((heading) => getHeadingStyle(heading) === "atx_closed");
|
||||
for (const atxClosedHeading of atxClosedHeadings) {
|
||||
validateHeadingSpaces(onError, atxClosedHeading, 1);
|
||||
validateHeadingSpaces(onError, atxClosedHeading, -1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue