Skip to content

Commit

Permalink
Reorder checks in filterByTypes helper predicate for ~2% runtime redu…
Browse files Browse the repository at this point in the history
…ction.
  • Loading branch information
DavidAnson committed Oct 24, 2024
1 parent d94b78e commit e6e799d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions helpers/micromark-helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e6e799d

Please sign in to comment.