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

@ -3,7 +3,8 @@
"use strict";
const { addErrorDetailIf } = require("../helpers");
const { filterByTypes, getDescendantsByType, getTokenTextByType } = require("../helpers/micromark.cjs");
const { getDescendantsByType, getTokenTextByType } = require("../helpers/micromark.cjs");
const { filterByTypesCached } = require("./cache");
const listStyleExamples = {
"one": "1/1/1",
@ -30,7 +31,7 @@ module.exports = {
"parser": "micromark",
"function": function MD029(params, onError) {
const style = String(params.config.style || "one_or_ordered");
for (const listOrdered of filterByTypes(params.parsers.micromark.tokens, [ "listOrdered" ])) {
for (const listOrdered of filterByTypesCached([ "listOrdered" ])) {
const listItemPrefixes = getDescendantsByType(listOrdered, [ "listItemPrefix" ]);
let expected = 1;
let incrementing = false;