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
|
@ -3,7 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext, addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes, getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
|
||||
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypesCached } = require("./cache");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
|
@ -25,11 +26,7 @@ module.exports = {
|
|||
let anyHeadings = false;
|
||||
const getExpected = () => requiredHeadings[i++] || "[None]";
|
||||
const handleCase = (str) => (matchCase ? str : str.toLowerCase());
|
||||
const headings = filterByTypes(
|
||||
params.parsers.micromark.tokens,
|
||||
[ "atxHeading", "setextHeading" ]
|
||||
);
|
||||
for (const heading of headings) {
|
||||
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
|
||||
if (!hasError) {
|
||||
const headingText = getHeadingText(heading);
|
||||
const headingLevel = getHeadingLevel(heading);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue