Skip to content

Commit e6e799d

Browse files
committed
Reorder checks in filterByTypes helper predicate for ~2% runtime reduction.
1 parent d94b78e commit e6e799d

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

demo/markdownlint-browser.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,7 @@ function filterByPredicate(tokens, allowed, transformChildren) {
806806
* @returns {Token[]} Filtered tokens.
807807
*/
808808
function filterByTypes(tokens, types, htmlFlow) {
809-
const predicate = (token) =>
810-
(htmlFlow || !inHtmlFlow(token)) && types.includes(token.type);
809+
const predicate = (token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token));
811810
const flatTokens = tokens[flatTokensSymbol];
812811
if (flatTokens) {
813812
return flatTokens.filter(predicate);

helpers/micromark-helpers.cjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ function filterByPredicate(tokens, allowed, transformChildren) {
124124
* @returns {Token[]} Filtered tokens.
125125
*/
126126
function filterByTypes(tokens, types, htmlFlow) {
127-
const predicate = (token) =>
128-
(htmlFlow || !inHtmlFlow(token)) && types.includes(token.type);
127+
const predicate = (token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token));
129128
const flatTokens = tokens[flatTokensSymbol];
130129
if (flatTokens) {
131130
return flatTokens.filter(predicate);

0 commit comments

Comments
 (0)