From e6e799d145414a03b60b374eec3820633c036e16 Mon Sep 17 00:00:00 2001 From: David Anson Date: Wed, 23 Oct 2024 21:44:36 -0700 Subject: [PATCH] Reorder checks in filterByTypes helper predicate for ~2% runtime reduction. --- demo/markdownlint-browser.js | 3 +-- helpers/micromark-helpers.cjs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 6d810f7eb..c52e419bc 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -806,8 +806,7 @@ function filterByPredicate(tokens, allowed, transformChildren) { * @returns {Token[]} Filtered tokens. */ function filterByTypes(tokens, types, htmlFlow) { - const predicate = (token) => - (htmlFlow || !inHtmlFlow(token)) && types.includes(token.type); + const predicate = (token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token)); const flatTokens = tokens[flatTokensSymbol]; if (flatTokens) { return flatTokens.filter(predicate); diff --git a/helpers/micromark-helpers.cjs b/helpers/micromark-helpers.cjs index 2d2aea551..eb868fe2f 100644 --- a/helpers/micromark-helpers.cjs +++ b/helpers/micromark-helpers.cjs @@ -124,8 +124,7 @@ function filterByPredicate(tokens, allowed, transformChildren) { * @returns {Token[]} Filtered tokens. */ function filterByTypes(tokens, types, htmlFlow) { - const predicate = (token) => - (htmlFlow || !inHtmlFlow(token)) && types.includes(token.type); + const predicate = (token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token)); const flatTokens = tokens[flatTokensSymbol]; if (flatTokens) { return flatTokens.filter(predicate);