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

@ -2,9 +2,9 @@
"use strict";
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } =
require("../helpers");
const { filterByTypes, getHeadingLevel } = require("../helpers/micromark.cjs");
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } = require("../helpers");
const { getHeadingLevel } = require("../helpers/micromark.cjs");
const { filterByTypesCached } = require("./cache");
const defaultLines = 1;
@ -41,12 +41,7 @@ module.exports = {
const getLinesAbove = getLinesFunction(params.config.lines_above);
const getLinesBelow = getLinesFunction(params.config.lines_below);
const { lines } = params;
const headings = filterByTypes(
// eslint-disable-next-line unicorn/consistent-destructuring
params.parsers.micromark.tokens,
[ "atxHeading", "setextHeading" ]
);
for (const heading of headings) {
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
const { startLine, endLine } = heading;
const line = lines[startLine - 1].trim();